When testing for bugs or searching for the root of email-related issues, it’s wise to rule out the possibility of an SMTP server malfunction. A simple way to gauge your SMTP server’s responsiveness is to connect to it via an application protocol like Telnet directly from your local computer, a way of checking if your server responds to commands as expected.
In this article, we’ll provide a bit of background on what SMTP and Telnet are and how you can use Telnet to help validate the email functionality in your applications.
What is SMTP?
Whenever you compose a message and click ‘send’ in an email client, your email service uses SMTP, or Simple Mail Transfer Protocol, to direct your message to where it needs to go.
This protocol is one of several TCP/IP protocols that govern how your computer connects to the internet (and ultimately to other computers). SMTP does the work of taking your email and relaying it from your device to its destination.
SMTP also plays a role in receiving email messages in conjunction with other TCP/IP protocols such as POP and IMAP. SMTP is used for sending emails, while POP and IMAP work to receive them.
What is Telnet?
Telnet, short for teletype network, is a networking protocol that allows a computer to access another one remotely. It provides a two-way channel for text-based communication between two (or more) devices.
Telnet uses a command prompt to access another computer or server through the syntax telnet hostname port. A user can then communicate to another computer or send commands to a server from even the most basic computer.
Before Telnet, it was necessary to physically walk to servers to extract data from them. Telnet made it possible to set up terminals that could communicate with other machines, significantly improving productivity in workspaces.
The protocol was first developed back in 1969—some 15 years before the inception of the Internet we all know today. some even say that Telnet was in a way the very first internet.
As a pre-Internet protocol, Telnet predictably does not offer anything in the way of encryption. Today, it’s often bypassed in favour of modern protocols due to the associated security concerns. The ubiquitous Secure Shell (SSH) protocol, which uses encryption and supports key-based authentication, was in fact designed to supplant Telnet itself.
Needless to say, Telnet bore witness to one of the first Requests for Comments (RFCs) with RFC 15 back in 1969. RFCs like RFC 15 are formal technical documents that paved the way for today’s modern computer networks. RFC 15 was extended in RFC 855 as the internet continued to evolve. There are over 8700 Requests for Comments in existence today.
Why is Telnet used to test SMTP servers?
Even in our modern era, Telnet can still be used to test email or web servers for functionality and bugs.
The Telnet protocol was the first and still one of the simplest ways to establish a Transmission Control Protocol (TCP) connection between devices. Further, Telnet allows the sending of plain-text information over a single TCP connection.
SMTP, as mentioned earlier, is a simple transfer protocol that also uses plain text. Telnet makes it possible to view the exact steps an SMTP client would follow when connecting to an SMTP server. Being able to see each step that the client follows facilitates the identification of issues and troubleshooting.
Next, let’s take a look at how to set up and use Telnet to test out your server.
Before you connect: which SMTP port to use
Before you connect to an SMTP server, you have two options: port 25 and port 587. But which one should you use?
Established in 1982, port 25 is the oldest and still the default SMTP port. This port is not encrypted and, as a result, is often blocked by internet service providers. This is done to ensure the privacy of server-client communications and reduce the chance of data being intercepted or manipulated by a third party.
Port 587 is the default port for encrypted SMTP connections. When your email client submits an email to be sent to another device through a mail server, port 587 is the port to use.
It’s also a good idea to use encryption to add extra security to outgoing mail. With SSL (Secure Sockets Layer) or TLS (Transport Layer Security) encryption, port 587 will ensure email is submitted securely.
Your app likely uses both SSL/TLS and port 587. If you’re looking to try out an SMTP connection, port 587 is the better option to use.
Setting up Telnet
Let’s now take a look at how to use Telnet to test out an SMTP server. As mentioned above, our example will use SMTP port 587.
For Windows: if you need to install Telnet to your computer, navigate to Control Panel, then Programs, and click ‘Turn Windows features on or off’. Scroll down to the option for the Telnet Client, and click the checkbox to enable it.
For Linux users, Telnet can be installed using Yum in Fedora and CentOS, or Apt on Debian and Ubuntu. To do so, run the following command:
$ yum -y install telnet # fedora / centos
$ apt-get install telnet # debian / ubuntu
Depending on how your Linux system is configured, you might need to use
sudo to run Yum or Apt with administrative privileges.
On a Mac, users with Homebrew installed can open a terminal and install Telnet using the following command:
$ brew install telnet
To start up Telnet, boot up a command prompt. From there, input the telnet command to launch the service.
Since your application will likely be using encryption on port 587, you’ll want to use an encrypted connection to see if it works as expected.
The best options for this are SSL or TLS. For our example below, we installed OpenSSL on our machine. Check out this short guide on installing OpenSSL on Windows. For Linux, you can install OpenSSL by using Yum or Apt in the same way as we installed Telnet above:
$ yum -y install openssl # fedora / centos
$ apt-get install openssl # debian / ubuntu
For Mac, we can use Homebrew once again:
$ brew install openssl
Now, let’s use Telnet and OpenSSL to connect to an SMTP server.
Example: using telnet to securely connect to an SMTP server
Let’s take a look at how everything we’ve learnt so far allows us to connect to an SMTP server.
For our example, we’re going to use a test email in our Mailosaur account.
To start, open a command prompt on your device. Here, we’ll input the following information, line-by-line:
$ openssl s_client -starttls smtp -connect mailosaur.io:587
mail from: email@example.com
rcpt to: firstname.lastname@example.org
Subject: This is a test
This is a test email to cheque SMTP connectivity.
Thanks so much,
The first command,
openssl s_client -starttls smtp -connect mailosaur.io:587, calls upon the Mailosaur server using the OpenSSL encryption protocol that we installed earlier. Should you wish to send your message unencrypted, you can use the following command instead:
telnet mailosaur.com 25
The 25 or 587 refer to the port we’re using to send our message through.
ehlo.mailosaur.net kicks off the process of sending an email message. It’s a way for email servers to identify each other. In our case, we want to make sure we’re communicating with the Mailosaur server. Once you hit ‘enter’, you’ll receive something like the following to show the connection has been established:
250-AUTH LOGIN PLAIN CRAM-MD5
mail from: email@example.com simply lists where the email is coming from. Telnet will respond with:
250 sender firstname.lastname@example.org OK
rcpt to: email@example.com states the destination of our email message. We’re using our Mailosaur test server to send one email, but commas can separate multiple addresses.
Telnet will let you know that it understands where the message needs to go:
250 recipient firstname.lastname@example.org OK
Putting in data and pressing the ENTER key starts the text you’d like to send. Typing
Subject: followed by the text of your choice will place that text in the email’s subject line.
To start the body of the email message, you’ll need to press ENTER twice at the end of your subject line. Like a traditional email, you can use as many lines as you need to type out your email. The text does not need to all fall on one line.
To send the email message, you’ll need to press ENTER twice at the end of the body of your text. Once you’ve accomplished this, put a period (
.) on the current line and press ENTER again.
This final step will send the message along to your recipient.
When should you use Telnet to test an SMTP connection?
As we demonstrated in our example above, Telnet is a great tool to test connectivity with an SMTP server. We can follow each step of the SMTP client to see what’s working and what isn’t.
Telnet may be simplistic in its design, but it works well for communicating with SMTP to see if your server is working correctly.
That being said, Telnet’s lack of security features still render it unsuitable for use with SMTP for anything other than testing.
Streamline your email testing with Mailosaur
Verifying SMTP functionality is an essential measure for any website that relies on sending emails to clients or customers. Telnet’s plain-text interface links up nicely with SMTP to test for connectivity.
Mailosaur makes it easy to test out your server’s functionality and responsiveness by allowing you to connect Telnet to any number of email addresses.
Get started with Mailosaur for your email and SMS testing today!