如何更改电子邮件地址字段?

时间:2010-09-22 22:09:41

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

我正在尝试使用姓名和电子邮件地址更改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]

3 个答案:

答案 0 :(得分:3)

SPUtility.SendMail将始终使用管理中心指定的from smtp地址&gt;传出电子邮件设置和友好名称设置为网站标题。

相反,您可以使用(来自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);

答案 1 :(得分:2)

我知道这个帖子已经过时了,但是如果有人遇到过这个问题,那么你的原始代码可以使用SPUtility.SendMail工作正常,如果你在from地址中的友好名称周围添加引号,如下所示:

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

答案 2 :(得分:1)

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

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