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

Published on 2019-08-19· Updated on 2022-08-16

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


SMTP connection errors could be resolved in numerous ways but command line detects the error from the root quite easily. In this conundrum, Telnet is widely used to test SMTP connection breaks. Testing an email server with Telnet client is where we would focus, going forward with our solution. In this article we would be solving one of the most widely searched issues and a potential SMTP connection pain point for the developers. To check if SMTP is working from the command line (Linux), is one critical aspect to be considered while setting up an email server.

The most common way of checking SMTP from Command Line is using telnetopenssl or ncat (nc) command. It is also the most prominent way to test SMTP Relay. Let's see how it works. 

Note: these commands are Linux specific, so won't work in other environments. 

SMTP From Command Line - Some Important Commands

1. Telnet:
 Used to communicate with another host using the telnet protocol. If the hostname is not provided it enters into command mode.

Note: If telnet is not available, copy and paste the command

sudo yum install telnet

2. ncat or nc: It's a general purpose CLI tool used for port scanning, security tool, and monitoring tool.
Note: If ncat or nc is not available, copy and paste the below command

sudo yum install nmap-ncat -y

3. openssl: It's a general purpose library that provides an open-source implementation of SSL and TLS protocol.
Note: If openssl is not installed, copy and paste the below command:

sudo yum install openssl

Step 1: Checking SMTP Connection Using Telnet

Telnet to your host, you want to check connection. Smtp servers usually communicate over smtp ports 25, 2525,587. Telnet SMTP test is one the best ways to figure out your SMTP connection state. 

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 ] 

In order  to quit telnet ctrl + ] and quit

Output: If it's getting connected properly 

You can even try sending email using telnet.

Output: If the connection is refused.

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

Because ncat or nc has various functionality from the list of functionality we will just check the connection using the following command.

nc -v -u 587

If it is successfully connected

[[email protected] auth]# ncat -v -u 587
Ncat: Version 7.50 ( )
Ncat: Connected to

If there is a problem connecting the host 

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

All of the above steps are used to check the SMTP connection from command line to a particular port of the host. The next step is used to communicate through a secure tunnel using TLS. TLS security is of paramount importance when it comes to email deliverability. Read our detailed blog on TLS Security (Highly Recommended). 

Step 3: Checking SMTP Connection Over TLS Using Openssl

In order to set up a TLS encrypted connection to an SMTP server, you need openssl command.

openssl s_client -connect -starttls smtp 

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

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

Consequently, once you got 250 DSN you can start now your SMTP transaction now by using 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.

These are some of the popular methods to check whether the SMTP connection is active on your machine. In case you have installed the SMTP correctly, but still getting an error while sending emails, then please refer this doc for more information.

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!

Get expert marketing tips straight to your inbox and become a better marketer. Subscribe to our Blog.
Let's Deploy
Get Started Now