System.Net.Mail SmtpClient c#

914 views Asked by At

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?

1

There are 1 answers

3
ThomasArdal On BEST ANSWER

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)