If you are a system administrator you probably manage one or more email servers so things eventually will go wrong and need to be resolved as quickly as possible. It is beneficial to know how to troubleshoot email servers using telnet via a shell so you don’t have to rely on a GUI mail client. Below I describe how to login to an Exim email server using telnet, authenticate via SMTP authentication, and then send test emails. The below examples will be run from a terminal window on Linux however they should be very similar too running the commands from a Command Prompt on Windows 7 or any other operating systems using a terminal window or similar.
Below we have displayed each step in the process followed by a completed log of the entire process including responses received from the mail server we are logging into.
Telnet To Exim Mail Server On Port 25:
- telnet mail.somedomain.com 25
Once connected to the mail server on port 25 using telnet you will need to introduce yourself to the mail server using a SMTP HELO or possibly a EHLO which are both very similar.
Introduce Yourself To The Mail Server Using EHLO:
After the introduction attempt to authenticate via SMTP Authentication which may or may not be required. Many mail servers now require that you login via SMTP Authentication if you have not sent credentials over POP in the past 30 minutes or 1 hours. To login via SMTP Authentication you will first be required to convert the username and password to base64-encoding which can be done using the commands below. If you have any special characters they will need a backslash in front of them such as the “@” symbol in the example below. Make sure that you type the below base64-encoding perl conversion , in a second terminal window outside of the telnet session.
Convert Username & Password To Base64-Encoding:
- perl -MMIME::Base64 -e 'print encode_base64("user\@mytestdomain.com")'
- perl -MMIME::Base64 -e 'print encode_base64("password321")'
Authenticate To The Mail Server With SMTP Authentication:
- AUTH LOGIN YWxleEBteWdlbml1c3R2LmNvbQ==
After authentication you will get a confirmation message back from the mail server that will state something similar to “Authentication Succeeded”. After you are authenticated you can begin the send email dialogue with the mail server as shown below.
Send Email Sender & Email Recepient:
- MAIL FROM:<firstname.lastname@example.org>
- RCPT TO:<email@example.com>
Send Email Contents Including Subject & Body:
- Subject: Test Exim Mail Server
- Hello Exim, Please enjoy this test.
Once you click enter after the “.” the email will send to the email address specified after “RCPT TO”. The mail server may close the connection immediately or you may be required to type “quit” followed by enter. Now that each command has been explained in detail above the below is a complete output from a Linux terminal window that will also display the mail servers responses so you can follow along.
Linux Terminal Output For Sending Email With SMTP Authentication Over Telnet:
- [root@dev ~]# telnet mail.maildomain.com 25
- Trying 192.168.35.139...
- Connected to mail.maildomain.com (192.168.35.139).
- Escape character is '^]'.
- EHLO220-fg.yetanotherdomain.com ESMTP Exim 4.69 #1 Thu, 29 Jul 2010 05:13:48 -0700
- 220-We do not authorize the use of this system to transport unsolicited,
- 220 and/or bulk e-mail.
- 250-fg.yetanotherdomain.com Hello sub.anothertestdomain.com [192.168.111.13]
- 250-SIZE 52428800
- 250-AUTH PLAIN LOGIN
- 250 HELP
- AUTH LOGIN Y87f4rJeWdlbml1c123LmUvbQ==
- 334 JGre2dvcnQ5
- 235 Authentication succeeded
- MAIL FROM:<firstname.lastname@example.org>
- 250 OK
- RCPT TO:<email@example.com>
- 250 Accepted
- 354 Enter message, ending with "." on a line by itself
- Subject: This is a test over telnet
- Hello. We are testing sending email via telnet on a mail server that requires SMTP Authtentication.
- 250 OK id=1OeS1P-0005Hp-N2
- 221 yetanotherdomain.com closing connection
- Connection closed by foreign host.
You should now be able to send and receive email without an Email client. This will assist you in pinpointing problems faster by not only having more information immediately but also by not filtering out the server error codes.