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.

Share:
12,035

Related videos on Youtube

Luke Le
Author by

Luke Le

I'm a software developer. In my professional life I mostly do C#.Net

Updated on June 04, 2022

Comments

  • Luke Le
    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
      Evk over 6 years
      For STARTTLS just do smtpClient.EnableSsl = true;
    • Luke Le
      Luke Le over 6 years
      @Evk Thank for your reply. So SSL ? Do you have any suggestions for me?
    • Evk
      Evk over 6 years
      If by SSL you mean connecting to 465 port (by default) - then it's not supported by SmtpClient.
    • Luke Le
      Luke Le over 6 years
      @Evk, I got it. Thank for your support.
  • Luke Le
    Luke Le over 6 years
    Thank for your reply. Maybe I will choose an exist third-party SMTP client components.
  • N_E
    N_E about 2 years
    @maxchiu, how did you come accross microsoft dev blog in your search ? It's a very sound information.