Test SMTP Relay

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. 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 are likely familiar with the term thanks to our blog post about SMTP relay. For those of you who didn’t have a chance to check it out, we’ll provide a brief explanation using the following infographics:

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. Usually, they are set up by SMTP relay services like Sendinblue or Mailgun for bulk email and transactional email sending. So, when you need to test SMTP relay, you must test of 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 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. 

Alternative, 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

smtp-cli

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 encryption settings of the TLS-enabled server with a subsequent user authentication. Doing this with telnet would be impractical. 

Installation

You can download the latest version of smtp-cli from GitHub releases page. Alternatively, you can use a download utility like 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] 'PIPELINING'
[250] 'SIZE 20480000'
[250] 'ETRN'
[250] '8BITMIME'
> QUIT
[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] 'PIPELINING'
[250] 'SIZE 10240000'
[250] 'VRFY'
[250] 'ETRN'
[250] 'AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5'
[250] 'AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5'
[250] 'XVERP'
[250] '8BITMIME'
AUTH method (PLAIN LOGIN DIGEST-MD5 CRAM-MD5): using CRAM-MD5
> AUTH CRAM-MD5
[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'
> DATA
[354] 'End data with <CR><LF>.<CR><LF>'
[250] 'Ok: queued as C5C3A299D7'
> QUIT
[221] 'Bye'

SMTP Server Connection Diagnostics Tool

Here is another telnet alternative that allows you to do SMTP relay check easily. It is an SMTP Server Connection Diagnostics Tool built by SocketLabs. It has a 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. 

Installation

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.

swaks

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.

Installation

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 [1.2.3.4]
[250] PIPELINING
[250] AUTH PLAIN CRAM-MD5
> AUTH CRAM-MD5
[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
> DATA
[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!
> QUIT
[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 for how to fix the error.

SMTP server checker by DNSQueries

This tool is useful to check 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”. 

SMTPer

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 an SMTP relay testing tool?

Mailtrap can do many things:

  • send test emails without reaching real inboxes
  • detect if your emails are spam
  • test HTML for support by basic email clients
  • organize test emails into special inboxes
  • run integrational or load email tests via API 
  • test Bcc in your emails 

But SMTP relay testing is not the case. Underneath Mailtrap there is a fake SMTP server. You can use it instead of a real server for testing the email sending capability of your app. This will prevent you from spamming real customers with test emails. For more about how you can benefit from Mailtrap, read the Getting Started Guide.