Test TCP Port 25 (smtp) access with telnet

From Thomas-Krenn-Wiki
Jump to: navigation, search

In this article we show you how to use telnet to test the access to a mail server on TCP port 25.

SMTP Protocol Basics

SMTP is a plain text protocol.[1][2] This makes it easy to simulate a mail client with the telnet command to check the access to port 25.

The following steps are required on a Linux command line:

  1. Execute telnet SERVERNAME 25. This connects telnet to port 25 on the server with the name SERVERNAME. The name or IP address of the server for a domain can be determined by dig DOMAIN -t MX. If there is no own MX record for a domain, the corresponding A-record must be used.
  2. If the TCP connection can be established, telnet responds with the message Connected to SERVERNAME. and Escape character is' ^]'. .
  3. Now you can send an e-mail via SMTP protocol. The best way to do this is to use a recipient address for which the connected mail server is responsible.
    1. EHLO test.example.com
    2. MAIL FROM:<SENDERADDRESS>
    3. RCPT TO:<RECIPIENTADDRESS>
    4. DATA
    5. Subject: Testmessage
    6. (Blank line, press Enter again)
    7. This is a test.
    8. (Blank line, press Enter again)
    9. .
    10. QUIT

Example

In the following example, an e-mail is sent to an e-mail address. In the example below, the domain example.com is used for documentation, please replace it with your mail server:[3]

[user@fedora9 user]$ telnet mail.example.com 25
Trying 192.0.2.10...
Connected to mail.example.com.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix (Debian/GNU)
EHLO test.example.com
250-mail.example.com
250-PIPELINING
250-SIZE 30720000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN DIGEST-MD5 PLAIN CRAM-MD5
250-AUTH=LOGIN DIGEST-MD5 PLAIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:<test@example.com>
250 2.1.0 Ok
RCPT TO:<user@example.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Testmessage

This is a test.

.
250 2.0.0 Ok: queued as 83398728027
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
[user@fedora9 user]$ 

References

  1. Simple Mail Transfer Protocol (en.wikipedia.org)
  2. RFC 5321 - Simple Mail Transfer Protocol (ietf.org)
  3. Example.com (en.wikipedia.org)

Author: Thomas Niedermeier

Related articles

Bash Tipps and Tricks
DRBD
HA Cluster with Linux Containers based on Heartbeat, Pacemaker, DRBD and LXC