【问题标题】:How to change email FROM address field?如何更改电子邮件 FROM 地址字段?
【发布时间】:2011-04-15 23:56:12
【问题描述】:

我试图用姓名和电子邮件地址更改 FROM 字段。但是当我收到邮件时,如下图所示

My network <commity@company.com [My network <commity@company.com]

Mycode如下

    const string from = "My network <commity@company.com>";

    StringDictionary headers = new StringDictionary();
       headers.Add("to", invitee.userEmail);
       headers.Add("subject", ltEmailSubject.Text);
       headers.Add("from", from);
       headers.Add("content-type", MediaTypeNames.Text.Html);

       _emailSuccessful = SPUtility.SendEmail(elevatedSite.RootWeb, headers,
                          emailBody + Environment.NewLine + "");

我想要的 FROM 电子邮件地址应该如下所示

My network [commity@company.com]

【问题讨论】:

    标签: c# asp.net sharepoint html-email


    【解决方案1】:

    我相信,如果您查看 .Net Framework 中的邮件对象,您可以做您想做的事情。

    Maybe this site 可以进一步帮助您吗?

    【讨论】:

      【解决方案2】:

      SPUtility.SendMail 将始终使用管理中心 > 外发电子邮件设置中指定的发件人 smtp 地址,并且友好名称设置为网站标题。

      您可以使用(来自http://www.systemnetmail.com/faq/3.2.1.aspx

      MailMessage mail = new MailMessage();
      
      //set the addresses
      //to specify a friendly 'from' name, we use a different ctor
      mail.From = new MailAddress("me@mycompany.com", "Steve James" );
      mail.To.Add("you@yourcompany.com");
      
      //set the content
      mail.Subject = "This is an email";
      mail.Body = "this is the body content of the email.";
      
      //send the message
      SmtpClient smtp = new SmtpClient("127.0.0.1");
      smtp.Send(mail);
      

      【讨论】:

        【解决方案3】:

        我知道这个帖子很旧,但如果有人像我一样遇到这个问题,如果您在发件人地址中的友好名称周围添加引号,您的原始代码将可以使用 SPUtility.SendMail 正常工作,如下所示:

        const string from = "\"My network\" <commity@company.com>";
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-08-18
          • 1970-01-01
          • 2012-09-28
          • 2011-09-09
          • 1970-01-01
          • 2023-02-21
          • 1970-01-01
          • 2020-08-16
          相关资源
          最近更新 更多