Search code examples
c#emailsmtpsmtpclientsystem.net.mail

System.Net.Mail SmtpClient c#


Does System.Net.Mail SmtpClient support smtp server with httpS or it work only with smtp servers with http?

I mean if i pass "https//:mysmtpserver" to constructor od SmtpClient instance - it would work?


Solution

  • SmtpClient works with SSL, yes. You need to provide it as a property like this:

    var smtpClient = new SmtpClient("smtp.gmail.com")
    {
        Port = 587,
        Credentials = new NetworkCredential("username", "password"),
        EnableSsl = true,
    };
        
    smtpClient.Send("email", "recipient", "subject", "body");
    

    (taken from this article How to send emails from C#/.NET - The definitive tutorial)