How to implements secure connections (No | SSL | STARTTLS) in SmtpClient to send mail?
12,035
.NET built-in mail class doesn't support the needed SSL method (implicit SSL) and there's nothing to do with this: the reason is explained here.
There exist third-party SMTP client components that do both explicit and implicit SSL , for example, AIM(Aegis Implicit Mail), or you should consider sending email through Gmail, Yahoo, Outlook, etc.
Related videos on Youtube
Author by
Luke Le
I'm a software developer. In my professional life I mostly do C#.Net
Updated on June 04, 2022Comments
-
Luke Le about 2 years
I use class SmtpClient of namespace System.Net.Mail to send mail: I create SmtpClient to send mail:
private static SmtpClient CreateSmtpClient (string host, string user, string password, int port) { var smtpClient = new SmtpClient (host, port); smtpClient.Credentials = new NetworkCredential (user, password); return smtpClient; }
and use it:
var mailMessage = new MailMessage (); var smtpClient = CreateSmtpClient (host, user, password, port); smtpClient.Send (mailMessage);
How to implements secure email transfer when I have 3 option secure connection is: No | STARTTLS | SSL ? Many thanks !
-
Evk over 6 yearsFor STARTTLS just do
smtpClient.EnableSsl = true;
-
Luke Le over 6 years@Evk Thank for your reply. So SSL ? Do you have any suggestions for me?
-
Evk over 6 yearsIf by SSL you mean connecting to 465 port (by default) - then it's not supported by SmtpClient.
-
Luke Le over 6 years@Evk, I got it. Thank for your support.
-
-
Luke Le over 6 yearsThank for your reply. Maybe I will choose an exist third-party SMTP client components.
-
N_E about 2 years@maxchiu, how did you come accross microsoft dev blog in your search ? It's a very sound information.