I'm trying to set up our no-reply email notification with our office 365 account. I've requested to admin to uncheck the SMTP auth and created the app password but still, I'm getting an error on sending an email. Email has MFA
SMTP config
- Username - the no-reply email account
- Password - app password generated from https://account.activedirectory.windowsazure.com/AppPasswords.aspx
- SMTP Host is smtp.office365.com
- PORT used is 587
Still throwing exception below
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 Client not authenticated to send mail. [HK2PR02CA0208.apcprd02.prod.outlook.com]
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress(fromAddress);
message.To.Add(new MailAddress(recipient));
message.Subject = subject;
message.IsBodyHtml = true; //to make message body as html
message.Body = content;
smtp.Port = port;
smtp.Host = host;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(userName, password);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);