Forum Discussion
Send Mail (SMTP) through Office 365 with MFA
You can still use Option one .. all what you have to do is generate an app password to by pass MFA.
Follow the steps in the below article ..
https://support.office.com/en-us/article/create-an-app-password-for-office-365-3e7c860f-bda4-4441-a618-b53953ee1183
Thanks
Robin Nishad
- Kazu1301Aug 14, 2019Copper Contributor
Hi Rnishat0786, it was the first thing I tried. In the same way I do with Outlook, I generated the app password and tried it with no success. I am creating a SecureString file (encrypted pwd file) and generating a PSCredential Object from it for authentication using Powershell, as follows (I hope the variables are self explanatory):
$SecureStringPassword = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$EmailCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SMTPUsername,$SecureStringPassword
....
Send-MailMessage -From $MailFrom -To $MailTo -Subject $MailSubject -Body $MailBody -Port $SMTPPort -Credential $EmailCredential -Attachments $Attachment
This approach works very well without 2FA, but not with app password. Do you see any mistake here or any changes that may work?
Regards
Kazu