mailservertest can be used to make testing mail servers a bit easier. It is a short script written in Python. Here a few use cases.
You’ve just restarted a number of mail servers, and you want to verify that they are delivering mail
mailservertest my.email@example.com mail1.example.com mail2 mail3
This will send a test email to my.email@example.com through the four mail servers mail1, mail2, mail3 and mail4. Note that the full domain name needs to be specified for the first mail server mail1.example.com; afterwards the ‘example.com’ will be appended to the remaining mail servers. This will save you some typing.
When you run the command, you will see output like this:
mail1.example.com
... Connecting to server ...
OK
... Sending the "helo" command ...
OK
... Sending the email ...
OK
mail2.example.com
... Connecting to server ...
OK
... Sending the "helo" command ...
OK
... Sending the email ...
OK
mail3.example.com
... Connecting to server ...
OK
... Sending the "helo" command ...
OK
... Sending the email ...
OK
The script verifies each step of the mail process for each server. Thus, you can see where in the process a problem is occurring. The -q option will turn off these messages, but error messages (if any) will still be shown.
The emails you receive will look like this
From: my.email@example.com
Subject: MAILTEST: mail1 16:28:29 2013-12-08
To: my.email@example.com
This is a test email
Tag : MAILTEST:
Date : 16:28:29 2013-12-08
All Recipients : my.email@example.com
All Servers : mail1.example.com mail2.example.com mail3.example.com
This Server : mail3.example.com
----------------------------------------------------
Sent from the script 'mailservertest'
on the host 'Your-Host'
The Subject line was chosen to make it as useful as possible when viewed in an email client; it shows the server that sent the message and the time that the script was run. The “tag” MAILTEST can be customized using the -t option.
You need to verify that your mail server rejects invalid addresses during the initial connection.
If your mail server should reject email for invalid addresses, you can verify that with this command (shown with it’s output).
mailservertest -q noone@example.com mail1.example.com
ERROR: {'noone@example.com': (550, '5.1.1 <noone@example.com>: Recipient address rejected: User unknown in virtual alias table')}
First note that the -q option has removed the status output shown in the previous example. Only the error message is shown; and it verifies that the address is unknown.
You want to generate and inspect a bounce message
You may be able to generate an email bounce message by sending an email through one mail server functioning as an MTA (mail transfer agent) to a second mail server functioning as a MDA (mail delivery agent). If the MTA passes your message to the MDA, and the recipient address is invalid, the MDA will return a bounce message to the return address. Since in this case the recipient address and the return address must be different, we will need to use the -f option to mailservertest. The -f option sets the return address. By default, the recipient and return address are the same; this worked fine for the previous example, but not now.
mailservertest -f my-email@example.com broken-email@other.com mail.example.com
Here, broken-email@other.com is an invalid email address. We first send the email to our MTA mail.example.com. It will send the email to whatever mail server handles other.com. The email bounce will be sent to our email address my-email@example.com. Below is an example of what is returned.
Delivery has failed to these recipients or groups:
broken-email@other.com
The e-mail address you entered couldn't be found. Please check the recipient's e-mail address and try to resend the message. If the problem continues, please contact your helpdesk.
Diagnostic information for administrators:
Generating server: CASHUBE.grove.ad.other.com
broken-email@other.com
#550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##rfc822;broken-email@other.com
Original message headers:
Received: from mail.example.com (192.168.25.234) by
CashubE.grove.ad.other.com (192.168.30.167) with Microsoft SMTP Server id
14.2.347.0; Sun, 8 Dec 2013 17:25:49 -0500
Received: from localhost (host.example.com [192.168.80.33]) by
mail.example.com (Postfix) with SMTP id 2F1007F44 for
<broken-email@other.com>; Sun, 8 Dec 2013 17:25:49 -0500 (EST)
From: "my-email@example.com" <my-email@example.com>
Subject: MAILTEST: mail 17:25:49 2013-12-08
To: <broken-email@other.com>
Date: Sun, 8 Dec 2013 17:25:49 -0500
MIME-Version: 1.0
Content-Type: text/plain
Message-ID: <e91f8c64-57e5-47db-a2bc-9857ce0c04f3@CASHUBE.grove.ad.other.com>
Return-Path: my-email@example.com
Reporting-MTA: dns;CASHUBE.grove.ad.other.com
Received-From-MTA: dns;mail.example.com
Arrival-Date: Sun, 8 Dec 2013 22:25:49 +0000
Original-Recipient: rfc822;broken-email@other.com
Final-Recipient: rfc822;broken-email@other.com
Action: failed
Status: 5.1.1
Diagnostic-Code: smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found
ForwardedMessage.eml
Subject:
MAILTEST: mail 17:25:49 2013-12-08
From:
"my-email@example.com" <my-email@example.com>
Date:
12/08/2013 05:25 PM
To:
<broken-email@other.com>
This is a test email
Tag : MAILTEST:
Date : 17:25:49 2013-12-08
All Recipients : broken-email@other.com
All Servers : mail.example.com
This Server : mail.example.com
----------------------------------------------------
Sent from the script 'mailservertest'
on the host 'host'
–