How to check SMTP connection from Command Line ( Linux )?

Published on 2019-08-19Β· Updated on 2024-01-25

The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.


The command line is a powerful tool for detecting and resolving SMTP connection errors. In this tutorial, we emphasize the importance of checking SMTP functionality from the command line in Linux when setting up an email server.

To effectively identify and troubleshoot SMTP connection issues, developers commonly rely on Telnet. It makes it easier to pinpoint any breaks in the SMTP connection.

 This tutorial demonstrates how to test an email server using a Telnet client. Other commonly used methods for checking SMTP Relay from the command line include OpenSSL and ncat (nc) commands. 

Note: These commands are Linux-specific and will not work in other environments.

SMTP From Command Line - Some Important Commands

1. Telnet:
 This application enables communication with a remote host using the telnet protocol. If a hostname is not provided, it will enter command mode.

Note: Copy and paste the command if telnet is not accessible.

sudo yum install telnet

2. ncat or nc: It is a versatile CLI tool for port scanning, security, and monitoring. It is a networking utility that enables data transfer across networks using TCP or UDP protocols.

By default, the TCP protocol is selected. However, if we wish to utilize the UDP protocol, we can easily do so by adding the -u option.

Note: Copy and paste the command if ncat or nc is not available

sudo yum install nmap-ncat -y

3. openssl: This general-purpose library implements open-source SSL and TLS protocols.
Note: copy and paste the command below if OpenSSL is not installed:

sudo yum install openssl

Step 1: Checking SMTP Connection Using Telnet

SMTP servers typically communicate over SMTP ports 25, 2525, and 587. Conducting a telnet SMTP test is considered one of the most effective methods for determining the state of your SMTP connection.

Did you know that SMTP Port 25 is the default SMTP Port? Read in detail.

Syntax : telnet [your hostname ] [port no]

telnet 25 [2525 | 587 ] 

To quit telnet, press ctrl + ] and quit.

The output will be as shown below only If everything gets connected properly. 

Step 2: Checking The SMTP Connection From Command Line Using Ncat Or Nc

To check the connection, we will use the following command.

nc -v -u 587

If it is successfully connected

[root@nl587 auth]# ncat -v -u 587
Ncat: Version 7.50 ( )
Ncat: Connected to

If there is a problem connecting to the host 

[root@nl587 auth]# ncat -v -u 587
Ncat: Version 7.50 ( )
Ncat: Could not resolve hostname "": Name or service not known. QUITTING.

The above steps enable checking the SMTP connection from the command line to a specific host port. The subsequent step involves establishing communication through a secure tunnel using TLS. Ensuring TLS security is crucial for maintaining optimal email deliverability.

Read our detailed blog on TLS Security (Highly Recommended). 

Step 3: Checking SMTP Connection Over TLS Using Openssl

You require an OpenSSL command to establish a TLS-encrypted connection with an SMTP server.

openssl s_client -connect -starttls smtp 

Once you hit the above command, you will see a lot of verbose.

Above all, you will notice a 250 DSN when a connection is established.

You can then start your SMTP transaction by using the below command

EHLO β€œi am here”
EHLO i am here
250-SIZE 50000000
250 DSN

this will give you supported verbose.

It will not respond if your SMTP server is not active.

The methods mentioned above are widely used to verify the status of the SMTP connection on your machine. If you have successfully installed the SMTP server but continue getting errors while sending emails, please refer to this doc for more information. 

If you have any queries or suggestions, please feel free reach out to [email protected] , and we would be happy to help you.

Excited about the latest in Bulk Email Marketing! Check out this insightful blog on Gmail and Yahoo updates in the email marketing landscape.
Explore the Blog - Here
Stay ahead of the game with valuable insights on optimizing your email campaigns! πŸ“¬

Grade My Email
Check your spam now?

Netcorecloud's toolkit is the solution to all your email problems.

Vikram Sahu πŸ¦‰

Developer Evangelist, Pepipost

πŸ’» Senior Software engineer β†’ πŸ₯‘ Developer Relations guy β†’ πŸ€“ Building Community for Email Geeks 🎟 β†’ Speaker πŸŽ™

You can also explore

Netcore connects & unifies your data across all sources, connects to your marketing channels and provides you with control over AI Powered automation and personalization.

Deploy emails that are
screenshot worthy!

Stop settling for static emails - use Netcore's platform to create dynamic, interactive emails that convert.
Let's Deploy
Get Started Now