Friday, February 12, 2016

5.5.1 Authentication Error in Gmail

Code for sending email using gmail in C# :

using System.Net.Mail;
using System.Net;

MailMessage mail = new MailMessage();
mail.From = new MailAddress("");
mail.Subject = "subject";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "foo foo bar";
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("", "gmail-password");
client.Port = 587;
client.Host = "";
client.EnableSsl = true;


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


Login to your gmail account from which you are trying to send email and then go to

Turn on access for less secure apps and error would be resolved.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.