0

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

try
{
    MailMessage mail = new MailMessage();
    string to = "dattatray96@gmail.com";
    mail.To.Add(to);
    mail.From = new MailAddress("dattatray96@gmail.com");
    mail.Subject = "Mail";
    mail.Body = " HI";

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
    smtp.EnableSsl = true;
    smtp.Send(mail);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message); Console.ReadLine();
}
jww
  • 97,681
  • 90
  • 411
  • 885
  • Try to use 2step varification form gmail setting and generate new password for your application – Vinit Patel Aug 18 '14 at 05:34
  • possible duplicate of [Sending email through Gmail SMTP server with C#](http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp) – Erik Philips Aug 18 '14 at 05:43
  • Lucky you have two factor verification on that account ;) You might want to consider editing your question and removing your password. – Tyler Durden Aug 18 '14 at 05:49
  • This is also right http://stackoverflow.com/a/9572958/3180471 This is perfect solution this works for me. – Vinit Patel Aug 18 '14 at 05:45

1 Answers1

2

Edit:

You first need to enable sending emails from your gmail account by following these steps


For SSL enabled gmail, you need to use the port:

465

Reference:

email.about.com

sameh.q
  • 1,691
  • 2
  • 23
  • 48
  • see here 5.5.1 authnatication error so no need to change port number – Vinit Patel Aug 18 '14 at 05:35
  • @Vap, check this out: [StachOverflow](http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page) – sameh.q Aug 18 '14 at 05:39
  • http://stackoverflow.com/questions/17227532/gmail-530-5-5-1-authentication-required-learn-more-at check this – Vinit Patel Aug 18 '14 at 05:40
  • 1
    @Vap, I think its neither my suggestion nor yours were wrong, both the answers are correct. see my updated answer for details – sameh.q Aug 18 '14 at 05:51