0

I was able to send emails with local smtp but when trying to send with gmail, it isnt working.

ERROR:

"The server rejected the sender address. The server response was: 530 5.7.0 
 Must issue a STARTTLS command first. pj7sm14546972pbb.96 - gsmtp\r\n"

C#:

public static void SendEmail()
{
  MailMessage mailMsg = new MailMessage();
  SmtpClient smtpClient = new SmtpClient();
  mailMsg.From = "donotreply@admin.com"; //also tried smtpusername here
  mailMsg.To = strToAddress;
  mailMsg.Subject = strSubject;
  mailMsg.Body = strBody;
  smtpClient.Port = 587;
  smtpClient.EnableSsl = true;
  smtpClient.Credentials = new NetworkCredential(smtpusername, smtppassword);
  //smtpusername & smtppassword are valid gmail credentials
  SmtpMail.SmtpServer = "smtp.gmail.com";
  SmtpMail.Send(mailMsg);
}
sukesh
  • 2,379
  • 12
  • 56
  • 111
  • possible duplicate of [The server response was: 5.7.0 Must issue a STARTTLS command first. i16sm1806350pag.18 - gsmtp](http://stackoverflow.com/questions/17462628/the-server-response-was-5-7-0-must-issue-a-starttls-command-first-i16sm1806350) – BCdotWEB Feb 16 '15 at 13:00

1 Answers1

0

If the EnableSsl property is set to true, and the SMTP mail server does not advertise STARTTLS in the response to the EHLO command, then a call to the Send or SendAsync methods will throw an SmtpException.

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl(v=vs.110).aspx

Inactive
  • 16
  • 2