0

I am trying to send a default passwords using smtp for users who want to retrieve their new passwords!

My Code :

public void SendUserPass()
{
    string sql = "Select Username, Password from Registration 
                  where Email='" + Email +   "'";
    DataTable table = new DataTable();
    table = db.RunQuery(sql);

    MailMessage message = new MailMessage("Esco@gmail.com", Email);
    message.Subject = "ESCO -Forgot Password";
    message.Body = "Username " + table.Rows[0][0].ToString() + "<br/> Password" +  
    table.Rows[0][1].ToString(); 

    message.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential("Esco@gmail.com", "Mypassword");
    smtp.EnableSsl = true;
    smtp.Send(message);
}

I get 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....

          Line 310:            smtp.Send(message);

Any help please ?

Community
  • 1
  • 1
Loay
  • 9
  • 3
  • Mandatory question: are you **absolutely sure** the login/password are correct? Have you verified that? – BartoszKP Nov 12 '14 at 23:26
  • Set it off but had the same error ! – Loay Nov 13 '14 at 00:07
  • 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) – mason Nov 13 '14 at 02:44
  • Please do not deface your posts. The code and error message provide important context here. – BradleyDotNET Dec 01 '14 at 16:44

1 Answers1

1

This worked for me

Login in to gmail ( in your case it is Esco@gmail.com)

visit

https://www.google.com/settings/security/lesssecureapps

Enable access to less secure apps

Rama Kathare
  • 920
  • 9
  • 29