【问题标题】:C# Send email using Office 365 SMTP doesn't change given email display nameC# 使用 Office 365 SMTP 发送电子邮件不会更改给定的电子邮件显示名称
【发布时间】:2019-05-18 19:30:02
【问题描述】:

我正在使用 C# MailMessage 通过 office 365 发送电子邮件,我想更改电子邮件中发件人的显示名称。

我尝试过像这样使用 mailMessage MailAddress 构造函数

mailMessage.From = new MailAddress("email","display name");

但这并不能解决问题

但当我尝试改用 Gmail 时,显示名称已更改。

【问题讨论】:

标签: c# outlook office365 sendmail mailaddress


【解决方案1】:

这是我们的通用 SMTP 电子邮件功能。它包括发件人的电子邮件地址和姓名。

 public static bool EmailReport(
               String Subject,
               String Body,
               String FromAddress,
               String FromName
               String[] To,
               String[] CC,
               out String sError)
        {
            MailMessage m = new MailMessage();
            SmtpClient smtp = new SmtpClient("<insert your email server name here i.e.: mail.Mycompany.com>");
            smtp.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            m.Subject = Subject;
            m.Body = Body;
            m.From = new MailAddress(FromAddress, FromName);
            foreach (String sTo in To)
            {
                m.To.Add(sTo);
            }
            if (CC != null)
            {
                foreach (String sCC in CC)
                {
                    m.CC.Add(sCC);
                }
            }
            try
            {
                smtp.Send(m);
                sError = "";
                return true;
            }
            catch (Exception ex)
            {
                sError = ex.Message + "\r\n\r\n" + ex.StackTrace;
                return false;
            }
        }

【讨论】:

  • Ahmad Jammal = 我们在 O365 上,从我们部署它的第一天起它就一直在工作。检查您的凭据是如何传递到函数中的。
猜你喜欢
  • 1970-01-01
  • 2019-12-22
  • 2016-04-09
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 2011-09-08
相关资源
最近更新 更多