skip to Main Content

Test SMTP connection with telnet PowerShell script

How to test SMTP communication with PowerShell? After you enable the SMTP service on the firewall for a specific system or configure an anonymous SMTP relay, you like to check that SMTP works. Telnet is your choice. But, what if you can use telnet wrapped in PowerShell? In this article, you will learn how to test SMTP communication with telnet PowerShell script.

Before you start

It’s good to verify that:

  • No antivirus or security products block SMTP connections
  • No firewall blocks SMTP connections

Download SMTP Telnet PowerShell script

Download the Test-SMTP-Telnet.ps1 PowerShell script or copy and paste the below code in Notepad. Give it the name Test-SMTP-Telnet.ps1 and place it in the C:\scripts folder. Create a script folder if you don’t have one.

After preparing the SMTP PowerShell script, you will test the SMTP connection with EHLO, and HELO commands.

Test SMTP connection

You like to know that SMTP works, and you need to test the SMTP connection. In this example, we will test the anonymous SMTP relay with port 25. You can enter a different port than port 25 and test the port that you like.

It’s important to run the SMTP Telnet PowerShell script on the client itself and not on the Exchange Servers.

For example, you add the Windows Server AP01-2016 IP address to the Exchange Server’s SMTP relay. The AP01-2016 server is an application server that sends emails to internal and external recipients. Log in on this server and run the Telnet PowerShell script.

Test SMTP connection with telnet PowerShell script remote IP address

In the internal DNS, an A-record is set up for that will translate to the load balancer. If you only have one Exchange Server or DNS round-robin, you most likely have the A-record pointed to your Exchange Server.

Test SMTP connection with telnet PowerShell script internal DNS A-record

Use the Exchange Server hostname, IP address, or the DNS record. In this example, will resolve to one of the Exchange Servers IP addresses.

HELO SMTP command

Start PowerShell on the system that is allowed to send an email. Start with the HELO command. It looks great because the sender and recipient response codes are both OK.

The below output is what you get when it’s not working. As you can see, there will be no response code 250 2.1.5 Recipient OK. Check your relay receive connector.

EHLO SMTP command

Do it again, but this time with EHLO. The response code 250 2.1.0 and 250 2.1.5 shows that the SMTP connection is good. If you don’t see those response codes, check your SMTP configuration.

SMTP port 25 not reachable

The following error shows up if port 25 is not reachable.

HELO SMTP command and sent an email to recipient

Send an email and verify that the message shows up in the recipient’s inbox. Make use of the parameter -Subject.

If you don’t get an email, check your SPAM folder or spam filter.

Read more: Exchange SMTP high availability with Kemp load balancer »


In this article, you learned how to test SMTP connection with telnet PowerShell script. It’s essential to save the STMP Telnet PowerShell script on the client/server you want to test on. Fill in the parameters and run the PowerShell script.

Did you enjoy this article? You may also like Exchange 2016 OWA your connection is not secure. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top