Test Office 365 email from command line

Modified on Mon, 11 Sep, 2017 at 6:32 PM

Press Windows key + R

Type "powershell" and hit Enter


Copy & Paste (after editing) this script:


$EmailFrom = “office-365-email-address@your-company.com”
$password = "office-365-email-password"
$username = $EmailFrom
$EmailTo = “your-unsuspecting-test-target@their-company.com”
$Subject = “The subject of your email”
$Body = “Testing Office 365 email...Please reply...”
$SMTPServer = “smtp.office365.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($username, $password);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)


Once triggered, confer with your willing test recipient to verify that they received the email. SMTP logs can be checked within Exchange Admin, and/or on the recipient's email server.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article