Search code examples
asp.netsmtpgmail

Sending email using ASP.NET I am getting this error


The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. u6sm344516ibd.6

I have my code like this?

MailAddress to = new MailAddress("[email protected]");
MailAddress from = new MailAddress("[email protected]");
MailMessage message = new MailMessage(from, to);
message.Subject = "Error Occred in the application:";
message.Body = ex.Message;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

Solution

  • You could check if setting the EnableSsl property for SmtpClient to true and specifying the credentials would help.

    client.EnableSsl = true;
    client.Credentials = new NetworkCredential("user", "password");