Last post May 21, 2020 04:42 AM by Sherry Chen
May 20, 2020 12:21 AM|Norkle|LINK
I have a .net core 2.2 app with identity package and email confirmation required for users who register. I was able to have this send successfully after configuring my gmail to "allow less secure apps" . Now I am receiving error :"The SMTP server requires
a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required " when new user registers. I have a class called emailsender that draws from appsettings.json file.
public interface IEmailSender
Task SendEmailAsync(string email, string subject, string htmlMessage);
public class EmailSender : IEmailSender
private readonly EmailSettings _emailSettings;
public EmailSender(IOptions<EmailSettings> emailSettings)
_emailSettings = emailSettings.Value;
public Task SendEmailAsync(string email, string subject, string message)
var credentials = new NetworkCredential(_emailSettings.Sender, _emailSettings.Password);
// Mail message
var mail = new MailMessage()
From = new MailAddress(_emailSettings.Sender, _emailSettings.SenderName),
Subject = subject,
Body = message,
IsBodyHtml = true
// Smtp client
var client = new SmtpClient()
Port = _emailSettings.MailPort,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = _emailSettings.MailServer,
EnableSsl = true,
Credentials = credentials
// Send it...
catch (Exception ex)
// TODO: handle exception
throw new InvalidOperationException(ex.Message);
"DefaultConnection": "Data Source=126.96.36.199;initial catalog=mydb;persist security info=True;user id=myusername;password=yyy;"
"SenderName": "My Company",
My gmail is configured for "allow less secure apps" , takes 587 for port via ssl
thanks in advance
May 20, 2020 10:43 AM|PatriceSc|LINK
You tried to log to Gmail to see if you have a warning message?
It can happen when deploying to a remote server. if Gmail sees a connection which is done from too far, too soon, it is handled as an hacking attempt. It should send a message about this and you can disallow that as well if needed.
Not directly related but you may want to consider at somepoint using https://github.com/jstedfast/MailKit which is is AFAIK able to handles the "modern GMail" authentication option.
Edit: this suggested at https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient?view=netcore-2.2#remarks
May 21, 2020 04:42 AM|Sherry Chen|LINK
Hi Norkle ,
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required
Check if the username and password are correct. And check whether the network status is good, the cause of the error may also be caused by connection timeout.
Refer to this answer which may be helpful. Perhaps, you can find
something useful on this System.Net.Mail FAQ too.