Sending certified mail (System.Web.Mail.MailMessage) on port 465 (tls1.2) only fails on windows server 2008 r2
I have a function based on the framework 4.5 but that uses an old library (System.Web.Mail.MailMessage) to send an email through a smtp server on port 465 (certified mail tls1.2), the function runs correctly on windows 10 and windows server 2012 but it fails on windows server 2008 r2. the error is of type System.Web.HttpException indicating that it can not reach the server but doing the telnet on port 465 works. What's wrong with 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) the transport failed to connect to the server
I solved by enabling the tls1.2 following this guide or this suggest by Imantas
In windows server 2008 R2 the tls1.2 protocol must be enabled by inserting in the system registry if not existing the following Key:
Under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols
Add Folder TLS 1.2 and in folder TLS 1.2 add subfolder Client and subfolder Server in both folders enter the DisabledByDefault
key set to 0
and the Enabled
key set to 1
User contributions licensed under CC BY-SA 3.0