How to test Office 365 SMTP server using PowerShell

Today I will show you how to test Office 365 SMTP server using PowerShell.

It is very easy to check if your SMTP Server is working correctly by simply utilizing PowerShell.

Let’s dive right in.

Step 1 - Running PowerShell

Start PowerShell by pressing the Windows Key and enter PowerShell. PowerShell is available on Windows XP onwards. It should be pre-installed on Windows 7 and 10.

Step 2 - Enter your Office365 User Credentials

Next, we are going to enter our Office365 User Credentials. That’s simply the email address you want to send from and your password.

In PowerShell, type:

Snippettext
$msolcred = get-credential

A credential window will pop up. Enter your Office 365 email address and password here.

How to test Office 365 SMTP server using Powershell
Enter your credentials

Step 3 - Sending the test mail

Now you need to enter the following command to send a test email:

Snippettext
Send-MailMessage –From mail@yourcompany.com –To user@yourcompany.com –Subject “Test Email” –Body “Test Text” -SmtpServer smtp.office365.com -Credential $msolcred -UseSsl -Port 587
How to test Office 365 SMTP server using Powershell
Sending the test mail

And there you have it. Now, if all worked correctly, you should receive your test mail.

Make sure you have a mailbox with Exchange Online Plan set up in Office365 for this to work.

whoami

Stefan founded Ceos3c in 2016 and has spent a decade teaching cybersecurity, Linux, and web development through hands-on tutorials. He builds and ships real products while sharing his journey: ProofSwap.me, XPMetric.com, and EasyEarningsTracker.com.

More about me