gpt4 book ai didi

c# - 如何从地址字段更改电子邮件?

转载 作者:行者123 更新时间:2023-11-30 14:41:48 25 4
gpt4 key购买 nike

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

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]

最佳答案

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

关于c# - 如何从地址字段更改电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3773993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com