This blog post was originally published on 02/07/2020 and was updated on 03/01/2022

How to Check an SMTP Connection with a Manual Telnet Session

In the world of email, there are many facets to testing, but one of the most basic tests you can do is to simply telnet into a given SMTP server.  This SMTP check is useful in determining if the most basic of problems do or do not exist.

  • Is the server up?
  • Is there a firewall blocking communication?
  • Does the mail server allow for relaying of a particular domain/email address?
  • What SMTP commands does the mail server support?
  • Does the server respond with the correct hostname?
  • Does the connection work outside any third-party software or APIs?

All these questions and more can be answered with a simple telnet test.

Before we get started, be sure to open up our companion piece to this post: To Where are Bounce Messages Sent? in a new tab so you can read it after you’re done with this blog.

As a note, the commands used in the following examples (as well as additional commands) are covered in section 4.1 of RFC 2821.

How Do I Send an Email Using Telnet?

Sending email through telnet can help you identify deliverability problems within your current configuration.

Sending email through telnet can help you identify deliverability problems within your current configuration.

Before you send an email using telnet, confirm telnet is both installed and enabled on your computer. Most computers come pre-installed with a telnet client. For those Windows versions that do not, one can be installed by opening the “Programs and Features” section of the control panel and selecting “Turn Windows features on or off”. With this window open, select “telnet client” and then click OK.

Once a telnet client has been verified to be installed on the server, open the terminal window where you’ll enter your prompt commands. On Windows, use the Windows + R, key in “cmd”, and press enter. For Mac users, you’ll find the terminal icon by opening Finder and searching for “Utilities” on the Applications page, or by entering “terminal” in the Launchpad search function.

Next, we need to find a mail server to log into. For this, we will need the DNS MX record for a given domain. This can be found with the following command (for these examples port25.com will be used, but any domain can be substituted):

Windows:

nslookup -type=mx port25.com

Non-authoritative answer:

port25.com  MX preference = 100, mail exchanger = mail.port25.com

Linux:

nslookup -type=mx port25.com

Non-authoritative answer:

port25.com  mail exchanger = 100 mail.port25.com.

SMTP uses one of three ports — 25, 465, or 587, which Microsoft Outlook commonly uses. If your SMTP relay uses a different port than 25 as shown in the example, you’ll use the port specified by the mail exchange server’s response to the nslookup. You can also verify the port your SMTP relies on by asking your administrator or logging into the mail exchange server and reviewing the protocols.

Next we need the DNS PTR for the IP we are going to use.  First we need to know what IP address the internet sees us as having.  To find that we can use a website like:

http://whatismyipaddress.com/

With the IP address run the following command, where A.B.C.D is the IP address.

Windows:

nslookup -type=ptr A.B.C.D

Non-authoritative answer: 

D.C.B.A.in-addr.arpa name = server.example.com

Linux:

nslookup -type=ptr A.B.C.D

Non-authoritative answer: 

D.C.B.A.in-addr.arpa name = server.example.com

server.example.com is just an example, and your results will be different.

So now that we have the MX record for port25.com and the PTR for the IP we are going to use, it is time to log in to the SMTP server.  To do so, use the following command:

telnet mail.port25.com 25

Something similar to the following should now be displayed:

Trying 69.63.149.30...
Connected to mail.port25.com (69.63.149.30).
Escape character is '^]'.
220 mail.port25.com (PowerMTA(TM) v4.0) ESMTP service ready

If you receive an error message like “cannot connect” at this point, either the port number is correct or the mail server is facing issues.

The first command we need to issue to the  mail server for our SMTP email tester is the EHLO  or HELO.  This is a basic greeting that starts the communication between the telnet client and the SMTP server.  Also passed is the DNS PTR for the IP address from which we are connecting as determined previously.

EHLO server.example.com

Something similar to the following should be returned:

250-mail.port25.com says hello
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250-8BITMIME
250-XACK
250-XMRG
250-SIZE 54525952
250-VERP
250 DSN

This shows the SMTP commands that the SMTP server accepts.  Not all SMTP servers support the same sets of commands. For example, yahoo only shows the following:

250-8BITMIME
250-SIZE 41943040
250 PIPELINING

And aol shows only one with:

250 DSN

The next command we need to issue is the MAIL FROM command.  This determines the address to which bounces are sent. This is not the same as the from header, which is the email address shown in an email client.

MAIL FROM: <support@port25.com>
250 2.1.0 MAIL ok

Ensure you use the domain name corresponding to your mail server's domain.

Ensure you use the domain name corresponding to your mail server’s domain. For example, if your email’s domain is anycompany.com, you’ll want to use you@anycompany.com instead of an outside email like you@free-mail-provider.com. Variations in domain names can cause an error message to appear.

Now that the MAIL FROM  command has been sent we can send the RCPT TO  command.  This command tells the SMTP mail server to who the message should be sent. This can be the same or different than the to header, which is the email address shown in the email client.

RCPT TO: <support@port25.com>
250 2.1.5 <support@port25.com> ok

Double-check your recipient’s address before sending the RCPT TO command — an error message displaying here can indicate a misspelled or blocked email recipient.

The last command to run before starting the body of the message is the DATA  command.  This command lets the SMTP mail server know that everything else about to be sent is the body of the message (which also contains the headers).

DATA
354 send message

It is important to note that if a mail server supports PIPELINING, as mail.port25.com does, the SMTP mail server may wait until the DATA command is issued before responding to any other commands after the EHLO/HELO.  In this case, enter the MAIL FROM, RCPT TO, and DATA  commands before waiting for a response.

Now that the DATA command has been sent we can start sending the message contents.  This starts with the various headers. At minimum a message should contain a to, from, subject, and date header. The headers entered here will be shown to the user in their email client.

From: "John Smith" <jsmith@port25.com>
To: "Jane Doe" <jdoe@port25.com>
Subject: test message sent from manual telnet session
Date: Wed, 11 May 2011 16:19:57 -0400

With the headers set, we now add one blank line with a carriage return/line feed (just press enter twice) and then we start the actual body of the message.

Hello World,
This is a test message sent from a manual telnet session.

Yours truly,
SMTP administrator

With the message complete, we need to tell the SMTP server that we are done with the message and want the SMTP mail server to accept it.  This is done with a period on a line by itself. If during the writing of a message a period on a line by itself is needed, you must put 2 periods, the first escaping the second.

.
 
250 2.6.0 message received

If you get an error message instead of the “received” notification, log the relevant details and contact your email provider for more assistance.

Lastly, the QUIT  command is sent to close the connection:

QUIT
221 2.0.0 mail.port25.com says goodbye

With that the mail server has now accepted the message for delivery, your telnet send email test is complete, and it should be sitting in the inbox of the RCPT TO address!!!

Here are all the commands without interruption:

telnet mail.port25.com 25
Trying 69.63.149.30...
Connected to mail.port25.com (69.63.149.30).
Escape character is '^]'.
220 mail.port25.com (PowerMTA(TM) v4.0) ESMTP service ready
EHLO server.example.com
250-mail.port25.com says hello
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250-8BITMIME
250-XACK
250-XMRG
250-SIZE 54525952
250-VERP
250 DSN
MAIL FROM: <support@port25.com>
250 2.1.0 MAIL ok
RCPT TO: <support@port25.com>
250 2.1.5 <support@port25.com> ok
DATA
354 send message
From: "John Smith" <jsmith@port25.com>
To: "Jane Doe" <jdoe@port25.com>
Subject: test message sent from manual telnet session
Date: Wed, 11 May 2011 16:19:57 -0400

Hello World,
This is a test message sent from a manual telnet session.
Yours truly,
SMTP administrator
.
250 2.6.0 message received
QUIT
221 2.0.0 mail.port25.com says goodbye

Sending an email using telnet lets you test connection capabilities quickly and at less cost than robust diagnostic equipment or software.

How Do I Test SMTP Using Telnet Authentication?

Now that you know how to check an SMTP connection with telnet, we’ll discuss authentication procedures. SMTP authentication helps prevent large amounts of spam from reaching reader inboxes, though not all mail exchange servers require it.

SMTP authentication helps prevent large amounts of spam from reaching reader inboxes, though not all mail exchange servers require it.

The primary difference in modern authentication protocols is the presence of a base64 encoding. Base64 converts binary data into the ASCII-text format required by mail servers for successful data transmission. It’s a way of representing your login credentials — some combination of text — in numeric format the computer can understand.

You can generate your base64 using software or free online tools. Once you communicate the information to the mail server, it compares this data with its records to determine authentication.

To test SMTP authentication via telnet, complete the following steps:

  • Open the terminal and connect with the mail server using the telnet server name and access command — mail.port25.com in the example above.
  • Greet the server with EHLO or HELO, enter AUTH LOGIN, and wait for the computer’s response.
  • Enter the base64-encoded user name and allow the server to answer.
  • Enter the password encoded in base64, and you should receive a response such as “authentication succeeded.”
  • Proceed with MAIL FROM, RCPT TO, DATA, and QUIT to send your authenticated email.

~ Scott