【发布时间】:2019-05-31 02:41:34
【问题描述】:
在端口 465 (tls1.2) 上发送认证邮件 (System.Web.Mail.MailMessage) 仅在 windows server 2008 r2 上失败
我有一个基于框架 4.5 的函数,但它使用旧库 (System.Web.Mail.MailMessage) 通过端口 465 上的 smtp 服务器发送电子邮件(认证邮件 tls1.2),该函数运行正确在 windows 10 和 windows server 2012 上,但在 windows server 2008 r2 上失败。该错误属于 System.Web.HttpException 类型,表明它无法访问服务器,但在端口 465 上进行 telnet 有效。 windows server 2008 r2有什么问题?
try
{
System.Web.Mail.MailMessage newMail = new System.Web.Mail.MailMessage();
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "server");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd");
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
newMail.From = "mail";
newMail.To = "mail";
newMail.Subject = "test web Mail";
newMail.BodyFormat = System.Web.Mail.MailFormat.Html;
newMail.Body = "body....";
newMail.Priority = System.Web.Mail.MailPriority.High;
System.Web.Mail.SmtpMail.SmtpServer = "smtpserver:465";
System.Web.Mail.SmtpMail.Send(newMail);
Console.WriteLine("Email Send");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
System.We.HttpException (0x80004005) 传输连接服务器失败
【问题讨论】:
-
smtpserver:465是您在代码中使用的实际值,还是您将其替换为实际的 smtp 服务器地址? -
smtpserver 是我报告的代码在 windows 10 和 windows server 20012 上插入正确参数的示例
-
另外,仔细检查服务器本身是否有TLS 1.2 is enabled。
-
GSerg 我尝试将以下行放在开头。 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;但它仍然不起作用。
标签: c# windows-server-2008-r2 tls1.2 mailmessage