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

发布于 2024-09-24 12:55:05 字数 1219 浏览 6 评论 0原文

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

My network <[email protected] [My network <[email protected]]

我的代码如下所示

    const string from = "My network <[email protected]>";

    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 + "");

我希望发件人电子邮件地址应显示如下

My network [[email protected]]

I was trying to change FROM field with Name and Email address. But When I receive the email, Its shown as below

My network <[email protected] [My network <[email protected]]

Mycode is like below

    const string from = "My network <[email protected]>";

    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 + "");

I want FROM email address should showup like below

My network [[email protected]]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幽蝶幻影 2024-10-01 12:55:05

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("[email protected]", "Steve James" );
mail.To.Add("[email protected]");

//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);

SPUtility.SendMail will always use the from smtp address as specified in Central Administration > Outgoing Email Settings and the friendly name is set to the title of the site.

Instead you can use (from 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("[email protected]", "Steve James" );
mail.To.Add("[email protected]");

//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);
身边 2024-10-01 12:55:05

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

const string from = "\"My network\" <[email protected]>";

I know this thread is old, but in case someone comes across this as I did, your original code would have worked fine using SPUtility.SendMail if you added quotes around the friendly name in the from address like this:

const string from = "\"My network\" <[email protected]>";
日暮斜阳 2024-10-01 12:55:05

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

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

I believe if you look at the mail object in the .Net Framework, you could do what you wish to do.

Maybe this site could help you out further?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文