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.7.0 Authentication Required

Tags:

c#

smtp

my website uses gmail smtp to send out emails. Nothing has been changed recently and all of a sudden it has stopped today. No code or password has been changed. This seems to be a common issue and many people suggest the same solution, unfortunately those didn't work for me today.

My SMTP code

using (var mail = new MailMessage())
{
    const string smtp = "smtp.gmail.com";
    const int port = 587;

    var loginInfo = new NetworkCredential(account, password);

    mail.From = new MailAddress(account);
    mail.To.Add(new MailAddress(toAddress));
    mail.Subject = subject;
    mail.Body = message.ToString();
    mail.IsBodyHtml = true;

    try
    {
        using (var smtpClient = new SmtpClient(smtp, port))
        {
            smtpClient.EnableSsl = KnownKeys.EnableSSL;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;
            smtpClient.Send(mail);
        }
    }

    finally
    {
        //dispose the client
        mail.Dispose();
    }

}

What I've tried

  1. Resetting password
  2. Setting smtpClient.TargetName = "STARTTLS/smtp.gmail.com";
  3. Double checked allow unsecure apps
  4. Verified Enabled SSL is on
  5. Tried port 465
like image 653
Master Avatar asked Dec 05 '25 21:12

Master


1 Answers

The problem is that you are running the application behind a firewall e.g Sophos so its blocking outbound communication from the application

like image 127
Kennedy Shabola Avatar answered Dec 07 '25 09:12

Kennedy Shabola