I have the following code inside my asp.net core MVC web application, to send an email using google smtp server:-
MailMessage mail = new MailMessage();
mail.From = new MailAddress("info@***.com");
mail.To.Add(new MailAddress("info@**.com"));
mail.Subject = "New Submission from Web Site";
mail.IsBodyHtml = true;
System.Text.StringBuilder mailBody = new System.Text.StringBuilder();
mailBody.AppendLine("<b>Dear Sirs, </b><br/><br/>");
mailBody.AppendLine(
"New Submission has been submitted from Web site. To view the new submission please click on the link <a href'https://*****/Submissions/details/" + sc.Submission.Id.ToString()
+ " <br/> <span style='font-weight:bold'>Regards</span> <br/> <span style='font-weight:bold'>Web Site</span>"
);
mail.Body = mailBody.ToString();
// Create a new Smpt Client using Google's servers
var smtpClient = new SmtpClient();
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
string smtpConn = configuration.GetSection("SMTP").GetSection("pass").Value;
smtpClient.Credentials = new System.Net.NetworkCredential
("info@****.com", smtpConn); // ***use valid credentials***
smtpClient.Send(mail);
but i got this error:-
SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at
any idea? although i am running the application from a machine where i can login to the gmail account from it...