更改显示名称C#以发送电子邮件

时间:2018-11-14 22:38:58

标签: c# email smtp office365

我正在使用C#发送邮件。我喜欢更改显示名称dinamic。

string sender = "myemail@domain.com";
            SmtpClient smtp = new SmtpClient("smtp.office365.com");
            smtp.Credentials = new System.Net.NetworkCredential(sender, "mypassword");
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;

            MailMessage mail = new MailMessage();
            MailAddress froms = new MailAddress(sender, "Name Name");
            //MailAddress froms = new MailAddress(sender, "Name Name", Encoding.ASCII);
            //MailAddress froms = new MailAddress(sender, "Name Name", Encoding.UTF8);
            //MailAddress froms = new MailAddress(sender, "Name Name", Encoding.Unicode);
            //MailAddress froms = new MailAddress(sender, "\\MyDisplayName\\");
            //MailAddress froms = new MailAddress(sender);                

            mail.From = froms;
            mail.Sender = new MailAddress(de);
            mail.To.Add(new MailAddress("to@domain"));
            mail.Subject = "TEST";
            mail.Body = "body";
            smtp.Send(mail);

但“名称名称”将被忽略,并且始终使用Outlook中配置的名称发送邮件

谢谢。

0 个答案:

没有答案