Forum Discussion
Client authentification failure while sending email from office365 account via powershell
- Jul 08, 2021
The regular way to do this when using modern authentication with MFA would be to allow ‘app passwords’. There are other ways, which I would not recommend, because they potentially lower the security posture.
If that doesn't work or is not allowed in your tenant, other methods may include:
* Disabling MFA (not recommended)
* If MFA is enabled using Azure AD Conditional Access, exclude this user for specifically SMTP from the Azure AD Conditional Access policy
* If you're using Security Defaults within your Microsoft 365 tenant, legacy authentication is blocked by default and can't be bypassed unless you disable Security Defaults
* You can use the Graph API for sending out e-mail programatically (Send mail - Microsoft Graph v1.0 | Microsoft Docs)
- rembermeJul 08, 2021Copper Contributor
pvanberlo, I'm trying commands below. Now I can use it or MailKit to send email after turning off the Authenticator approval. How can I achieve it when authenticator is turning on?
$cred = Get-Credential $mail = @{ SmtpServer = 'smtp.office365.com' Port='587' UseSSL=$true From='user@domain' To='targetuser@emailserver' Subject='subject' Body='body' } Send-MailMessage @mail # or Use MailKit, see https://adamtheautomator.com/powershell-email/
- pvanberloJul 08, 2021Steel Contributor
The regular way to do this when using modern authentication with MFA would be to allow ‘app passwords’. There are other ways, which I would not recommend, because they potentially lower the security posture.
If that doesn't work or is not allowed in your tenant, other methods may include:
* Disabling MFA (not recommended)
* If MFA is enabled using Azure AD Conditional Access, exclude this user for specifically SMTP from the Azure AD Conditional Access policy
* If you're using Security Defaults within your Microsoft 365 tenant, legacy authentication is blocked by default and can't be bypassed unless you disable Security Defaults
* You can use the Graph API for sending out e-mail programatically (Send mail - Microsoft Graph v1.0 | Microsoft Docs)