23/04/2015 by Nitesh

Solution: The server response was: 5.7.0 Must issue a STARTTLS command first. i16sm1806350pag.18 – gsmtp

Friends,

When sending emails via code using Gmail as mail server, we sometime get this error. This blog post explains the error and the solution to the same.

Reason:
The error occurs when the code tries to authenticate Gmail server using the given credentials over non-SSL layer and does not encrypt the connection.

Solution:
To resolve this, you need to set EnableSsl property of your SmtpClient class’s object to true as mentioned below –

  SmtpClient client = new SmtpClient("smtp.gmail.com");
  client.EnableSsl = true;

Hope you like this. Keep learning and sharing! Cheers!