0

I know this may sound like a duplicate but I HAVE TRIED EVERYTHING my code is below

MailMessage mail = new MailMessage("XXXXXXXXX@gmail.com", "XXXXXXXX@gmail.comm");

SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.Credentials = new NetworkCredential("XXXXXXX@gmail.com", "yyyyyyyYYYYY");
client.EnableSsl = true;

mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";

System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
    return true;
};

client.Send(mail);

The error happens on this line of code:

client.Send(mail);

Error code is 5.5.1. I also tried turning allow less secure apps ON

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Possible duplicate of [Sending email in .NET through Gmail](https://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – derpirscher Jul 14 '18 at 09:35

3 Answers3

0

Here is the answer, read more

the error might occur due to the following cases:

case 1: when the password is wrong

case 2: when you try to log in from some App

case 3: when you try to log in from the domain other than your time zone/domain/computer (This is the case in most of scenarios when sending mail from code)

amir mehrabi
  • 21
  • 1
  • 5
0

In this thread someone found out this can happen if your Gmail password is too weak. He changed his password -> his code worked. He changed it back: Google wouldn't allow the password.

Then, for an experiment, I tried changing my password back to my previous password to see what would happen, and Gmail didn't actually allow me to do this, citing the reason "sorry we cannot allow you to save this change as your chosen password is too weak" and wouldn't let me go back to my old password.

So: Try changing you Google password.

Vincent Vancalbergh
  • 3,267
  • 2
  • 22
  • 25
-1

Could it be a sender that is wrong, @ gmail.comm?