C# send email using implicit ssl
Solution 1
System.Net.Mail does support "explicit SSL" (also known as "StartTLS" - usually on port 25 or 587), but not "implicit SSL" (aka "SMTPS" - usually on port 465).
As far as I know, explicit SSL starts from an unsecured connection, then the STARTTLS command is given and finally a SSL secured connection is made. Implicit SSL, on the other side, requires that the SSL connection is set up before the two parties start talking.
Some servers (like gmail) accept both, so you simply need to set EnableSsl to true and send to the right port. If your server does not support explict SSL, though, this "simple way" is not an option.
I'm also still looking around for a general solution for using System.Net.Mail with implicit SSL, with no luck so far.
Anyway take a look at this article, it may give you some insight.
[edit: @Nikita is right, fixed port numbers to avoid confusion]
Solution 2
Use the TLS port (ie 587) rather than the SSL port. I had the same issue for months until I found this solution.
Sending email in .NET through Gmail
Solution 3
You may still be able to use the deprecated System.Web.Mail.MailMessage
API (and set its "http://schemas.microsoft.com/cdo/configuration/smtpusessl"
option, for explicit SSL/TLS):
System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage();
// ...
mailMsg.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
true);
Alternatively, if you can, you could run something like stunnel locally to establish an SSL/TLS tunnel from your localhost
to your SMTP server. Then, you would have to connect normally (without SSL/TLS) to the tunnel's localhost
end as your SMTP server.
Solution 4
Try to check AIM (Aegis Implicit Mail) on https://sourceforge.net/p/netimplicitssl/wiki/Home/
Radu D
Updated on June 07, 2022Comments
-
Radu D almost 2 years
Is there any library preferable free that can be used in order to sens email using implicit ssl protocol. My hosting provider support ssl emails ... but standard .net email client cannot handle that.
-
Dragomok over 7 years+1 I have seen port 587 several times, but no source mentioned that you should choose it even when your mail provider recommends other ports.
-
Nikita about 7 yearsimplicit usually running on port 465, and explicit - on port 25/587
-
Alessandro over 4 yearsThat's amazing, you just saved my life!!
-
Shiv about 3 yearsBut what if 587 is blocked? But 465 is available?