Scenario: Let’s consider I am using SMTP connection in c# to send mail from on office account. Due to the recent authentication after 2 factor authentication, accounts password cannot be used to send mail. In this case, app password has to be created for an office 365 account.
As mentioned in my earlier blog, Demystifying SMTP Error: Secure Connection Requirement – Athen we can use SMTP with office 365 credentials also. Let’s see below steps to rectify the “Secure connection requirement” error while sending mail using office credential (username and password)
MailMessage message = new MailMessage();
message.From = new MailAddress("<from mail>","<Display name>");
message.To.Add("<To mail>");
message.Subject = "Test";
message.Body = "Welcome";
message.IsBodyHtml = true;
SmtpClient SmtpClient = new SmtpClient();
SmtpClient.Credentials = new System.Net.NetworkCredential("<from mail>","<Password>");
SmtpClient.Host = "smtp..office365.com";
SmtpClient.Port = 587;
SmtpClient.EnableSsl = true;
SmtpClient.Send(message);
For office account with 2 Factor authentication enables, we need to create app password. Let’s see how app password can be created for Office 365 account.
Steps:
1.In Microsoft Admin center ->Active Users ->Select user ->Multifactor Authentication
Select the user -> Under Quick steps choose “Enable”, after enabling choose “Enforce”.
2.Choose “Manage user settings” ->check “Restore multi-factor authentication on all remembered devices”.
3.In Azure portal ->AAD->Properties->Manage security defaults->Choose “Disabled”
4.Once all the above steps are enabled,
Go to Azure portal ->View account->Security Info ->Add sign in Method ->App password->Enter a name for the App password.
Password will be generated automatically, and it can be used in the applications for logins.
The same app password can be used in the network credentials. This can also be used to solve “Demystifying SMTP Error” with office 365 credentials.
Limitations:
-App passwords are autogenerated.
-Only 40 passwords can be generated per user. If needed more, existing passwords has to be deleted.
References:
Manage app passwords for two-step verification – Microsoft Support
Hope this helps in creating App password in Office 365 account and usage of it in SMTP client.
No Comment! Be the first one.