Learn how to connect to Office365 on port 587 and send a test email using Powershell.

Troubleshooting or testing an Office365 SMTP issue can be simply tested by using the following 2 lines of code, the first line creates a variable where you enter your Office365 mailbox credentials then the second command uses the credentials to send a test email to the specified recipient.

Firstly open up Powershell (Must be v3 or greater), then copy/paste the following command,

$creds = get-credential 

When prompted, enter the Office 365 username and password which you plan to run the test from.

Once these credentials are stored in a variable, copy and paste the next snippet replacing the FROM field with your Office365 account that you have just specified in your credentials then specify a valid TO address,

Send-MailMessage –From <O365 email address> –To <Recipient email address> –Subject "Test Email" –Body "Test SMTP Service from Powershell on Port 587" -SmtpServer smtp.office365.com -Credential $creds -UseSsl -Port 587

All being well the email should be successfully delivered.

If you get the following error message when running the command, you need to ensure you are running Powershell version 3 or greater

Send-MailMessage : A parameter cannot be found that matches parameter name 'Port'.