Reputation: 9
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("[email protected]", 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("[email protected]", "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 ?
Upvotes: 0
Views: 133
Reputation: 930
This worked for me
Login in to gmail ( in your case it is [email protected])
visit
https://www.google.com/settings/security/lesssecureapps
Enable access to less secure apps
Upvotes: 1