Test SMTP Relay

On September 24, 2019
7min read
Artur Hebda Full Stack Developer @Railsware

Chances are you’re reading this blog post after you’ve googled “how to test SMTP relay”. Do you recall your search results? They mostly deal with email servers, SMTP connection, and using Telnet for testing those. We’ve systematized all the aspects you might be seeking and provided a detailed answer to your inquiry. So, let’s start with the basics.

What is the difference between SMTP relay and SMTP server?

SMTP relay is the process of routing emails to the proper destination SMTP server. It is not a software nor an app, unlike mail transfer agents that participate in the email delivery flow. Relay happens between the MSA and the MDA if the sender and the recipient come from different domains (handled by different SMTP servers). If the email is transferred within the same domain with no additional server involved, it doesn’t count as an email relay.

Some of you will already be familiar with the term thanks to our blog post about SMTP relay. For those of you who have not had a chance to check it out, we’ll provide a brief explanation using the following infographics:

NB: If you need to refresh your knowledge of the difference between IMAP vs. POP3 vs. SMTP, then check out our dedicated blog post.

In practice, the term SMTP relay often refers to the SMTP relay server, also known as a mail transfer agent (MTA). An MTA is an SMTP server that enables relaying. So, when you need to test SMTP relay, you must test the actual SMTP server that relays emails. In this case, the SMTP relay and the SMTP server can be deemed as synonyms, and thus Google treats them as interrelated terms.

What is an open relay test?

Besides checking the SMTP connection, you also need to verify whether your server is an open relay. What does this entail? The SMTP server should have an authentication mechanism that allows relaying emails to a different server. As a rule, if the server requests credentials (username and password) to perform the relay, it is NOT an open relay server. Open relay makes your server accessible to unauthorized users. Spammers will be able to send unsolicited emails from it. Such malicious activity will drop your IP address reputation, which is crucial for good email deliverability. Your open relay server may be blacklisted, and many SMTP servers will not accept emails from it.

So, how can I do the open relay test? You can telnet to the server and send an email to another domain using the MAIL FROM and RCPT TO commands. If the final response code is 250 and no authentication was requested, your server is an open relay. 

Alternatively, easier tests can be done with the following online tools:

Can I test SMTP relay with telnet only?

Telnet is the most common way to check whether the mail server allows for relaying of a particular domain. We’ve blogged about using it in How to Test SMTP Server. In most cases, telneting to your SMTP server will be enough to diagnose basic connection issues. Nevertheless, Telnet has its specific drawbacks:

  • no encryption – you have to build authentication strings manually using a MIME tool
  • frequent disconnection from the server
  • no macros with built-in SMTP commands
  • limitations related to SSL and TLS connection

With that in mind, we decided to put Telnet away and introduce other ways to troubleshoot SMTP relay. 

Test SMTP relay server connection with installable tools


This is an SMTP command line client. smtp-cli supports STARTTLS, SMTP-AUTH, and many other advanced features. Also, you can use this powerful tool for testing and debugging SMTP servers. It is a good alternative to telnet because smtp-cli allows you to check the encryption settings of the TLS-enabled server with a subsequent user authentication. Doing this with telnet would be impractical.


You can download the latest version of smtp-cli from GitHub releases page. Alternatively, you can use a download utility like a widget and install it with an appropriate command: 

$ wget -o smtp-cli https://github.com/mludvig/smtp-cli/releases/{LATEST_RELEASE}
$ chmod +x smtp-cli

Since some smtp-cli features are optional, check the required Perl modules and install them. The dependencies are specified on the GitHub page of the tool. For example, users of Ubuntu should install the following packages:

$ sudo apt install  libio-socket-ssl-perl  libdigest-hmac-perl  libterm-readkey-perl libmime-lite-perl libfile-libmagic-perl libio-socket-inet6-perl

SMTP relay test

Let’s check out how smtp-cli works. First, we’ll test the localhost. We’ll connect to the server and observe the basic SMTP back and forth. 

$ ./smtp-cli --verbose --server localhost
[220] 'localhost ESMTP Postfix'
> EHLO localhost
[250] 'localhost'
[250] 'SIZE 20480000'
[250] 'ETRN'
[250] '8BITMIME'
[221] 'Bye'

Now, we’ll test the relay. We’ll try to send an email through the server that requires authentication. That’s how the SMTP session will look:

$ ./smtp-cli --verbose --host smtp.example.com:587 --enable-auth --user test
--from test@example.com --to user@test.org --data message.txt

[220] 'smtp.example.com ESMTP Postfix'
> EHLO localhost
[250] 'smtp.example.com'
[250] 'SIZE 10240000'
[250] 'VRFY'
[250] 'ETRN'
[250] 'XVERP'
[250] '8BITMIME'
[334] 'PDE0OTQyOTcxOC4yNjAwOTYwQHNlcnZlci5kb21haW4udG9wPg=='
> dGVzdCBmOTUyY2RkM2VlODBiMzk1YjYxNDI4NjBlYzg2Y2ExZnJvb3Q=
[235] 'Authentication successful'
Authentication of test@localhost succeeded

> MAIL FROM: <test@example.com>
[250] 'Ok'
> RCPT TO: <user@test.org>
[250] 'Ok'
[354] 'End data with <CR><LF>.<CR><LF>'
[250] 'Ok: queued as C5C3A299D7'
[221] 'Bye'

SMTP Server Connection Diagnostics Tool

Here is another telnet alternative that allows you to do SMTP relay checks easily. It is an SMTP Server Connection Diagnostics Tool built by SocketLabs. It has built-in authentication, supports open and SSL connections, and is more secure than telnet. Moreover, you don’t have to manually type all the commands required to test relaying. The tool has a library of macros, which facilitates the testing flow.


In this case, you don’t have to install the tool. You only need to download and run it. This is how it looks:

SMTP relay test

  • Step 1: Connect to the server

Select Actions in the left-hand corner of the tool and click Connect. Enter your SMTP server information: server name and port. Keep the LocalIp option as a default. Click Connect.

  • Step 2: Test relaying

Use the built-in command macros to send an email from your SMTP server. Actually, the flow is the same as with telnet. The difference is that you don’t have to do everything manually.


This is the all-purpose SMTP transaction tester abbreviated from Swiss Army Knife SMTP. swaks is a command-line tool written in Perl for testing SMTP setups. It’s a real dinosaur tool – the first version came out in 2003. Nevertheless, it’s been updated many times and now handles numerous SMTP features and extensions like TLS, authentication, pipelining, and many more. If iterating telnet smtp.example.com 25 takes too long, swaks is definitely what you need.


Execute the following to install swaks on Ubuntu:

apt-get install swaks

on macOS

brew install swaks

SMTP relay test

Let’s say you have an SMTP server smtp.example.com that allows relaying for authenticated users. You can test this as follows:

swaks --to external-user@yahoo.com \
   --from=john@example.com \
   --auth \
   --auth-user=john \
   --auth-password=hell-no \
   --server smtp.example.com

This is how the conversation will look:

[250] smtp.example.com Hi remote.server.name []
[334] PGQ4ZcakejQ5ZDcheeseiQHNreC54ZW4taG9zpiesZy5uZXQ+
> c3RldsubliminalZmZDMxZmVkNmJjswimM2M4M2VkM2IsmileMDg=
[235] Authentication successful for john - Authenticated john; relaying permitted
> MAIL FROM:<john@example.com>
[250] <john@example.com>, sender OK - how exciting to get mail from you!
> RCPT TO:<external-user@yahoo.com>
[250] <external-user@yahoo.com>, recipient ok
[354] go ahead
> Date: Sun, 05 Apr 2019 21:24:34 +0100
> To: external-user@yahoo.com
> From: john@example.com
> Subject: Test email
> X-Mailer: swaks v20181104.0 jetmore.org/john/code/#swaks
> This is a test mailing
> .
[250] Queued!
[221] closing connection
=== Connection closed with remote host.

Web-based tools to test SMTP relay

Testing gets much easier with web-based tools. For most of them, you only need to enter your SMTP server and click the button to get things done. Besides, some of them let you test the server for the open relay! Here are the most worthwhile options.

Mail Server Testing Tool by DNS EXIT

DNS EXIT provides a suite of static/dynamic DNS services and other email-related solutions. With their Mail Server Testing Tool, you can telnet to your SMTP server and try to deliver the message. If there are some configuration flaws, the tool will let you know and give you a hint on how to fix the error.

SMTP server checker by DNSQueries

This tool is useful for checking the health status of the SMTP server. Also, it will let you know if everything is running correctly and the server is not an open relay. Enter the hostname of your SMTP server and click Run tool. It will try to connect to the server and send emails through it. We took the Gmail SMTP server and checked it with DNSQueries tester. Here is how the results are displayed:

MX toolbox

SMTP Diagnostics tool by MXToolbox works in a similar way. Just enter your SMTP server name and click Test Email Server. Here is a sample of the test result:

Also, it displays the session transcript below.

This is an integrated tool that tests MX record, DNS, blacklist and SMTP in one go. If you want to perform a particular test or lookup, use a special command, for example, “blacklist: smtp.example.com”.


Simplicity is the Ultimate Sophistication” – this quote by Leonardo Da Vinci shines on top of the SMTPer home page. You need to fill in several fields to use this SMTP relay testing tool: 

  • SMTP host
  • Port
  • Sender’s email address 
  • Recipient’s email address

Optionally, you can select “Use Secured Connection” and “Use authentication” (having specified Login and Password). SMTPer is a simple tool, but it can get the job done.

Is Mailtrap Email Sandbox an SMTP relay testing tool?

Mailtrap Email Sandbox, as a straightforward solution for email testing, can do many things, such as:

  • Organize your test emails into multiple inboxes for different projects and stages of those projects
  • Catch all emails from staging to inspect and debug them
  • Preview emails and check their content spam score
  • Validate email HTML/CSS
  • Check the presence of sender IP on common blacklists
  • Show original values of headers and SMTP transaction details
  • Forward messages manually or automatically to whitelisted recipients

As you can see, SMTP relay testing is not what Mailtrap Email Sandbox is intended for. Instead, if you’re looking to do automated email testing with zero risk of spamming recipients, then it is the solution you should be using.

Email Sandbox will also save time as its setup takes only about 5 minutes, and you don’t have to do things manually anymore.

So how do you get started with Email Sandbox? You have three options:

  1. In your Mailtrap account, go to Sandbox -> Inboxes -> SMTP Settings. There you can pick a framework from the list of integrations. This will generate a code sample containing the hostname, port number, username, and password you then need to paste into your email-sending script. 
  2. Also under SMTP Settings, you can find the SMTP credentials of your Email Sandbox virtual inbox by clicking the Show credentials link. These should be pasted into your email-sending script, MTA settings, email client settings, or some other system that supports SMTP credentials.
  3. Users of the Business and higher Email Sandbox plans have an email address dedicated to each of their virtual inboxes they can send emails to. These are activated under Sandbox -> Inboxes -> Email Address.  

Once you’ve decided on any of the setup options described above, complete the necessary steps and send your first email. If the email appears in your Email Sandbox virtual inbox, congrats! You have successfully completed the setup and now have a safe environment for testing your emails before sending them to recipients. Plus, you can stop using your personal inbox for the same purpose, thus preserving your domain reputation.

Article by Artur Hebda Full Stack Developer @Railsware