Use PowerShell to Send email from O365 Account

Prior to PowerShell 5.0 to send an email you had to use the .NET System.Net.Mail namespace. Now with PowerShell 5.0 and higher you can easily send email messages using the cmdlet Send-MailMessage. . You can use any valid SMTP server but for our example we'll use an O365 account. Just make sure you set your smtp address to smtp.office365.com and port to 587 and you should be all set.

Note: Make sure you use -UseSSL or else you'll receive a 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