'C#. SMTP The server response was: 5.7.0 Authentication Required
Error: The SMTP server requires a secure connecton or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at.
private void SendMail(string email, string firstname)
{
MailAddress from = new MailAddress($"{email}", $"{firstname}");
MailAddress to = new MailAddress($"{email}");
MailMessage m = new MailMessage(from, to);
m.Subject = "TEST";
m.Body = "<h2>TEST</h2>";
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new NetworkCredential("[email protected]", "password");
smtp.EnableSsl = true;
smtp.Send(m);
}
I want to send a letter to the mail, but the error that I indicated above comes out, here is the code, can you tell me what is wrong?
Solution 1:[1]
I see that your email is @mail.ru and the server is gmail, is that correct? I think you need to use your gmail account. You also need enable weaker credentials on your gmail account. Forgot what they actually call it but it's on gmail security setting.
Solution 2:[2]
I had also faced the same problem.
- Your SmtpClient is gmail, but you are using "[email protected]"!!!
- Make sure to set "Less secure app access" to ON in your Gmail security setting.
In my case, the problem was solved.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kevin Wolsey |
| Solution 2 | ouflak |
