gpt4 book ai didi

c# - 将 System.Web.Mail 功能移植到 System.Net.Mail

转载 作者:行者123 更新时间:2023-11-30 17:24:43 25 4
gpt4 key购买 nike

以下函数完美运行:

    protected void SendWebMailMessage(string DisplayName, string From, string ReplyTo,
string To, string Subject, string Body, string Attachments)
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver",
"smtpout.secureserver.net");
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",
2);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", From);
msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword",
mailpassword);
msg.To = To;
msg.From = DisplayName + "<" + From + ">";
msg.BodyFormat = MailFormat.Html;
msg.Subject = Subject;
msg.Body = Body;
msg.Headers.Add("Reply-To", ReplyTo);
SmtpMail.SmtpServer = "smtpout.secureserver.net";
SmtpMail.Send(msg);
}

但是,我收到构建警告,告诉我 System.Web.Mail 已过时,并且我应该使用 System.Net.Mail。所以我使用了 System.Net.Mail,然后我想出了以下函数替换我的旧函数:

    protected void SendNetMailMessage(string DisplayName, string From, string ReplyTo, 
string To, string Subject, string Body, string Attachments)
{
MailAddress addrfrom = new MailAddress(From, DisplayName);
MailAddress addrto = new MailAddress(To);
MailAddress replytoaddr = new MailAddress(ReplyTo);
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = addrfrom;
msg.To.Add(addrto);
msg.ReplyTo = replytoaddr;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtpout.secureserver.net");
smtp.Credentials = new NetworkCredential(From, mailpassword);
smtp.Send(msg);
}

我没有收到任何异常或错误,但我的消息从未通过。任何人都可以告诉我我可能做错了什么?提前致谢。

最佳答案

如果我没记错的话...您正在使用 Goddady 托管服务。我也在使用它...并且我有 **relay-hosting.secureserver.net** 作为 SMTP 服务器。我不知道...可能是这样的...或者您没有在您的控制台中设置中继。

关于c# - 将 System.Web.Mail 功能移植到 System.Net.Mail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/632763/

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