-1

I am trying to send an e-mail using c# MailKit SMTP (code below). It connects successfully (with Connect method) and then it fails on Authenticate method call with an error " Username and Password not accepted.". I know the user name and password are correct. I also tried "mail.optusnet.com.au" server on port 25 - same story. What is wrong with my call to smtp.Connect method. I have spent whole day experimenting and got nowhere. Can somebody help please.

// send email
using var smtp = new SmtpClient();
smtp.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);

smtp.Authenticate("rejkid@gmail.com", "Password1");

smtp.Send(email);
smtp.Disconnect(true);  
Janusz Dalecki
  • 197
  • 1
  • 10

1 Answers1

0

Google no longer allows your password to be used when authenticating via SMTP, POP3 or IMAP.

You either need to use OAuth2 or you need to enable 2FA on your Google account and then generate an app-specific password and use that.

jstedfast
  • 35,744
  • 5
  • 97
  • 110