1
System.IO.StringWriter myStringWriter = new System.IO.StringWriter(new System.Text.StringBuilder());
HtmlTextWriter myTextWriter = new HtmlTextWriter(myStringWriter);

StringBuilder sb = new StringBuilder();
sb.Append("Hello");
string Body= sb.ToString();

MailMessage myMessage = new MailMessage();
myMessage.To.Add("edf@gmail.com");
myMessage.Subject = "Registration Successfully Completed";
myMessage.Body = Body;
myMessage.IsBodyHtml = true;

using (SmtpClient smtp = new SmtpClient())
{
   //smtp.EnableSsl = true;
   smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc@46");

   smtp.Host = "smtp.gmail.com";
   smtp.Port = 587;
   smtp.UseDefaultCredentials = true;
   smtp.EnableSsl = true;
   smtp.Send(myMessage);
}

I am getting this error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Sagar Zala
  • 4,854
  • 9
  • 34
  • 62
Pooja Shah
  • 11
  • 4
  • Please check this post - https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not#26709761 – Nirman Feb 23 '18 at 10:25

0 Answers0