Hi Team
I have this method and have enabled my authentication on my gmail, still get this exception;
- public Task SendAsync(IdentityMessage message)
- {
-
- var mailMessage = new MailMessage();
- mailMessage.To.Add(new MailAddress(message.Destination));
- mailMessage.From = new MailAddress("[email protected]");
- mailMessage.Subject = message.Subject;
- mailMessage.IsBodyHtml = true;
- mailMessage.Body = message.Body;
- using (var smtp = new SmtpClient())
- {
- var credential = new NetworkCredential
- {
- UserName = "[email protected]",
- Password = "***"
- };
- try
- {
- smtp.Host = "smtp.gmail.com";
- smtp.Port = 587;
- smtp.EnableSsl = true;
- smtp.UseDefaultCredentials = false;
- smtp.Credentials = credential;
- smtp.Send(mailMessage);
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- return Task.FromResult(0);
- }
- }
System.Net.Mail.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'