Simulate sending an email

Detailed manual e-mail procedure

For diagnostic purposes, it can be very useful to simulate the sending of an email to a mail server, in order to understand why an email fails to reach a recipient’s mail server. In this article, we’ll describe a detailed procedure for simulating the sending of an email, with the aim of debugging such a situation.

This operation must be carried out in 2 stages: DNS request, sending the mail itself. These two steps are imperative. It would be a big mistake to avoid the first step, DNS analysis, just because you already know the name of the destination server. What’s more, these steps must be carried out from the sending mail server, to ensure that the DNS servers used for the queries are indeed the same, and that the sending IP address corresponds to the one seen by the destination server.

First step: find out the name of your mail server
You need to know the name(s) of the mail server that handles mail for the domain name you’re interested in. This is entered in the MX field(s) of the DNS zone that manages the domain name.

If you are using Windows :
Using the nslookup command :
C:>nslookup
> set q=MX
> domain.ltd
The system returns a list of MX fields
> exit
The main server is the one with the lowest priority.

If your mail server’s operating system is Linux :
You can use the dig or host commands:
# host -t MX domain.ltd (or) # host -t MX domain.ltd

Example:
root@a10:~# host -t MX airfrance.fr
airfrance.fr mail is handled by 10 smtp1.airfrance.fr.
airfrance.fr mail is handled by 20 smtp2.airfrance.fr.

AirFrance’s main mail server is: smtp1.airfrance.fr.

Second step: simulate sending an email
Once you know the name or IP address of the mail server, you can simulate sending an e-mail using the telnet command on port 25, which is the SMTP protocol port.

Example of a correctly transmitted e-mail:

# telnet mail.domaine.ltd 25
220 banner.domaine.ltd ESMTP
helo toto.com
250 ok
mail from: utilisateur@domaine.ltd (valid email address)
250 2.1.0 Ok
rcpt to: nom@domaine.ltd (email address valid in the tested domain)
250 2.1.5 Ok
data
354 Enter mail, end with “.” on a line by itself
test mail sending (mail text)
. (to finish the mail)
250 2.0.0 Ok: queued as 3FE2C8181C9
quit
221 2.0.0 Bye

Example of an error message (anti-relay) :

# telnet mail.domaine.ltd 25
220 banner.domaine.ltd ESMTP
helo toto.com
250 mail.domaine.ltd
mail from: toto@yahoo.com
250 sender <toto@yahoo.com> ok
rcpt to: titi@gmail.com
550 #5.1.0 Address rejected.

For details of the SMTP protocol, see the following article: here

The codes returned by mail servers are of 3 types:
2xx = acceptance
4xx = temporary refusal (e.g. Greylisting )
5xx = permanent refusal (usually followed by an error message, which may be more or less explicit)

In this example, the mail server has responded with a code 250, so the mail is accepted and its identifier in the server is 3FEC8181C9. You can press “quit” instead of data, so that no e-mail is sent and you have checked the validity of the address.

ALTOSPAM has developed an interesting tool, freely accessible here, to simulate the whole procedure. In this case, the test is obviously not performed from your mail server, but it does give a very good indication of the remote domain’s configuration.

The article here shows how to use our online tool to validate a recipient’s domain or email address.

Test Altospam’s solutions!

Thousands of companies, CTOs, CIOs, CISOs and IT managers already trust us to protect their e-mail against phishing, spear phishing, ransomware, …