通过SMTPClient发送电子邮件时需要更改FromEmail字符串

时间:2009-09-18 10:11:37

标签: c# asp.net email smtpclient

我的电子邮件发送代码

 MailMessage msg = new MailMessage("mailer@abc.com", "xyz@hotmail.com", "testing email", "to check from email label text");
    SmtpClient smpt = new SmtpClient();
    smpt.Send(msg);

当电子邮件由xyz@hotmail.com用户打开时,在来自电子邮件中,其中提到了mailer@abc.com,我需要在其中显示 Abc Corporation [abc@nextech.pk] < / p>

如何更改电子邮件地址标签

由于

2 个答案:

答案 0 :(得分:2)

使用真实姓名和电子邮件地址创建一个MailAddress,然后将其提供给MailMessage。

从MSDN(From property for MailMessage)。

  MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
  MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
  MailMessage message = new MailMessage(from, to);

答案 1 :(得分:1)

使用DisplayName

MailMessage m = new MailMessage();
m.From = new MailAddress("mail@mailserver.com", "My Mail");