Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the SMTP server requires a secure connection or the client was not authenticated. The server response was 5.5.1, Authentication required

Tags:

c#

smtp

gmail

I have been trying to get my application to send an email for over an hour now, and i've tried everything i've found online but i still get the exception mentioned in the title of my question.

Here is the code i used:

        SmtpClient client = new SmtpClient();
        client.Host = "smtp.gmail.com";
        client.Port = 587;
        client.Credentials = new NetworkCredential("Sender email", "Sender email password");
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("Sender email", "Sender");
        mail.To.Add(new MailAddress("My email"));
        mail.Subject = "TEST";
        mail.IsBodyHtml = true;
        mail.Body = sb.ToString();

        client.Send(mail);

I have allowed access to less secure apps on my account. I have also tried enabling 2FA and then generating an application specific password, but the exception stays.

like image 807
chrisstar123 Avatar asked Dec 06 '25 03:12

chrisstar123


1 Answers

  1. Check your gmail account and turn on "Acess for less secure apps"

  2. Set client.UseDefaultCredentials = false; before client.Credentials = new NetworkCredential("Sender email", "Sender email password");

like image 119
ISHIDA Avatar answered Dec 07 '25 16:12

ISHIDA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!