In this article I 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:
- 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 bydig DOMAIN -t MX
. If there is no own MX record for a domain, the corresponding A-record must be used. - If the TCP connection can be established, telnet responds with the message
Connected to SERVERNAME.
andEscape character is' ^]'.
. - 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.
EHLO test.example.com
MAIL FROM:<SENDERADDRESS>
RCPT TO:<RECIPIENTADDRESS>
DATA
Subject: Testmessage
- (Blank line, press Enter again)
This is a test.
- (Blank line, press Enter again)
.
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:
[[email protected] 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:<[email protected]> 250 2.1.0 Ok RCPT TO:<[email protected]> 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.