Meghana M

Meghana M

  • 1.2k
  • 175
  • 23.1k

Mail is not triggering using C# code

Nov 10 2023 6:11 AM

Error for mail triggering:System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; the Client was not authenticated to send anonymous mail during MAIL FROM'

Code :

using (SmtpClient smtp = new SmtpClient())
                    {

                        smtp.Port = _configuration.GetValue<int>(Constants.EmailServer + Constants.Port);
                        smtp.Host = _configuration.GetValue<string>(Constants.EmailServer+Constants.SmtpHost);
                        smtp.EnableSsl = true;
                        smtp.UseDefaultCredentials = false;
                        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                        await smtp.SendMailAsync(message);
                    }

values are set in appsettings.json


Answers (5)