This post is really more about the potential problems one might encounter using Send-MailMessage cmdlet in PowerShell to connect and send email via Office 365.
First a quick example:
[SecureString]$o365Password = ConvertTo-SecureString "Your Office 365 Account Password" -AsPlainText -Force [PSCredential]$o365Credentials = New-Object System.Management.Automation.PSCredential("Your Office 365 Account Username",$o365Password) Send-MailMessage ` -Subject "Your Subject" ` -Body "Your email message" ` -To "toSomeone@somewhere.com" ` -From "fromSomeone@somewhereelse.com" ` -SmtpServer "outlook.office365.com" ` -Port 587 ` -Credential $o365Credentials ` -UseSsl
If the above settings are set correctly the email should be sent.
Some errors you may encounter:
Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [XXXXXXXXXXXXXXX.XXXXXXXX.prod.outlook.com]
Send-MailMessage : Unable to connect to the remote server
An information technology professional with twenty four years experience in systems administration, computer programming, requirements gathering, customer service, and technical support.