Title: Use Telnet as a Client
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Use Telnet as a Client

The telnet program can be used as a client for email, and it can be very effective for troubleshooting email problems.  Here is an example telnet session used to send email.

[carl@tinman ~]# host -t mx carltm.com
carltm.com mail is handled by 25 mail.carltm.com.
[carl@tinman ~]# telnet mail.carltm.com 25
Trying 50.57.116.138...
Connected to mail.carltm.com.
Escape character is '^]'.
220 cee.carltm.com ESMTP Sendmail 8.14.4/8.14.4; Fri, 21 Nov 2014 08:36:04 -0500
helo tinman
250 cee.carltm.com Hello hal.carltm.com [76.242.102.73], pleased to meet you
mail From: carl@carltm.com
250 2.1.0 carl@carltm.com... Sender ok
rcpt To: carl@carltm.com
250 2.1.5 carl@carltm.com... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Subject: this is a test message

This is a test message.  Notice that headers such as the subject appear
at the top of the input and are separated by a blank line from the body
of the message.
.
250 2.0.0 sALDa49J026730 Message accepted for delivery
quit
221 2.0.0 cee.carltm.com closing connection
Connection closed by foreign host.
[carl@tinman ~]#

In the above transaction,

- The first step is to find the MX record for the domain of the recipient.  If there is no MX record for the domain, use the domain name instead.
- The telnet command will connect to the hostname of the lowest numbered MX record or the domain name.  If the connection cannot be made, verify the email address, ensure that the domain has valid A or AAAA records, and that port 25 connections are allowed.  The nmap command is helpful for testing port 25 connections.
- Upon successful connection, the remote server will identify itself.  Read this output carefully, since many mail servers will notify you if there is a problem and perhaps give a URL for more information.
- The server will not prompt you, but you'll need to type the "helo" command followed by your hostname.  Often servers will disconnect the session if helo is not issued immediately.
- In response to the helo command, the server will again identify itself.  And again it does not prompt for another command.
- Type the command "mail" followed by "From: " and the sender's email address.  If there is a problem, an error message will be printed.  Otherwise a "Sender ok" message will appear.
- Type the command "rcpt" followed by "To: " and the recipient's email address.  If there is a problem, an error message will appear.  Otherwise "Recipient ok" will be printed.
- Type the command "data", and the server will prompt you to include the message.
- Include any headers at the top followed by a blank line.  Next type in the body of the message followed by a single dot (.) at the beginning of a line.
- At this point a message should appear showing that the email is queued for delivery.  Some spam filters will reject email at this point, so read the output carefully.  Notice that a serial number will appear if the message is accepted.  If you need assistance from the remote server's administrators, be sure to include the serial number which was generated by their server.  This will make it easier for them to search the logs.