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

3
我试图更改发件人的名称和电子邮件地址,但当我收到电子邮件时,它显示如下:
My network <commity@company.com [My network <commity@company.com]

我的代码如下

    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个回答

3

SPUtility.SendMail总是使用在Central Administration > Outgoing Email Settings中指定的发件人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);

2

我知道这个帖子很旧了,但是如果有人像我一样遇到了这个问题,你原来的代码只需要在发件人地址中友好名称的周围添加引号就可以使用SPUtility.SendMail正常工作,例如:

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

1

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

也许这个网站 可以帮助你更进一步?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接