Sending an email through a Web or Client interface is easy. I’m going to show you how to send an email manually via telnet.
I am going to keep it basic, as I don’t want to make this a long drawn out book about MX and MTA’s.
So lets get to it…
- MTA (Mail/Message Transfer Agent) – Wikipedia Link
- MX (Mail Exchange) Record – Wikipedia Link
In a nut shell, MTA’s are the routers of the Mail world. MX records show the MTA’s where to send which email to which domain (for example: yahoo.com or gmail.com).
I am going to use Yahoo’s MX/MTA‘s for this example. Let’s say I want to send an email from my gmail.com account to my yahoo.com account.
You first need to figure out the MX record(s) for yahoo.com. There is more than one way to figure this out, but I will show you three ways: dig, host, and nslookup.
$ dig mx yahoo.com +short | sort 1 e.mx.mail.yahoo.com. 1 f.mx.mail.yahoo.com. 1 g.mx.mail.yahoo.com. 1 h.mx.mail.yahoo.com. 1 i.mx.mail.yahoo.com. 1 j.mx.mail.yahoo.com. 1 k.mx.mail.yahoo.com. 1 l.mx.mail.yahoo.com.
$ host -t mx yahoo.com | sort yahoo.com mail is handled by 1 e.mx.mail.yahoo.com. yahoo.com mail is handled by 1 f.mx.mail.yahoo.com. yahoo.com mail is handled by 1 g.mx.mail.yahoo.com. yahoo.com mail is handled by 1 h.mx.mail.yahoo.com. yahoo.com mail is handled by 1 i.mx.mail.yahoo.com. yahoo.com mail is handled by 1 j.mx.mail.yahoo.com. yahoo.com mail is handled by 1 k.mx.mail.yahoo.com. yahoo.com mail is handled by 1 l.mx.mail.yahoo.com.
Note: The -t is for type.
$ nslookup > set type=mx > yahoo.com Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: yahoo.com mail exchanger = 1 e.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 f.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 g.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 h.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 i.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 j.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 k.mx.mail.yahoo.com. yahoo.com mail exchanger = 1 l.mx.mail.yahoo.com. Authoritative answers can be found from: > exit
Keep in mind that all the MTA’s are sitting behind each single MX record. There can be as few as one MTA or even hundreds behind any single MX record.
Now that you’ve got the MX records, you can then send an email manually via telnet.
WARNING: If you manage to mess up a certain amount of times (lets say 3-5), your IP may get deferred for about 5-10 minutes by the domain provider. The key is to do it quickly or the MTA will timeout due to inactivity.
Example of a deferred email attempt:
$ telnet e.mx.mail.yahoo.com 25 Trying XXX.XXX.XXX.XXX... Connected to e.mx.mail.yahoo.com. Escape character is '^]'. 421 4.7.0 [GL01] Message from (XXX.XXX.XXX.XXX) temporarily deferred - 4.16.50. Please refer to http://postmaster.yahoo.com/errors/postmaster-21.html Connection closed by foreign host.
Sending an email via telnet:
Note: ENTER means press the Enter Key. DO NOT TYPE ENTER.
Sending Format using Yahoo! as an Example:
$ telnet e.mx.mail.yahoo.com 25 ENTER HELO yahoo.com ENTER MAIL FROM:<username1@gmail.com> ENTER RCPT TO:<username2@yahoo.com> ENTER DATA ENTER from:username1@gmail.com ENTER to: username2@yahoo.com ENTER Subject: Test Email ENTER This is a test email ENTER . ENTER QUIT ENTER
Format Breakdown:
telnet e.mx.mail.yahoo.com 25 | Connecting to MX/establishing connection |
HELO yahoo.com | Introduce yourself to the MX |
MAIL FROM: <username1@gmail.com> | Tell the MX your email address, or who the email is from. |
RCPT TO: <username2@yahoo.com> | Tell the MX who the email is to, or who the email is to. |
DATA | Tell the MX that you are ready to write the main parts of the email (from, to, subject, and body), which is called the DATA. |
from:username1@gmail.com | Tell the recipient your email address, or who the email is from (for reply and visual purposes). – Not required |
to:username2@yahoo.com | Tell the recipient who the email is to, or who the email is to (for visual purposes). – Not required |
Subject: Test Email | Subject – Not required |
This is a test email | Body – Not required |
. | Type a . (period) to close the session. |
QUIT | Type QUIT to end the session. |
The Actual Send
I substituted the from and to email addresses for obvious reasons.
$ telnet l.mx.mail.yahoo.com 25 Trying 74.6.136.244... Connected to l.mx.mail.yahoo.com. Escape character is '^]'. 220 mta1232.mail.sk1.yahoo.com ESMTP YSmtp service ready HELO yahoo.com 250 mta1232.mail.sk1.yahoo.com MAIL FROM:<username1@gmail.com> 250 sender ok RCPT TO:<username2@yahoo.com> 250 recipient ok DATA 354 go ahead from:username1@gmail.com to: username2@yahoo.com Subject: Test Email This is a test email . 250 ok dirdel quit 221 mta1232.mail.sk1.yahoo.com Connection closed by foreign host.
4 replies on “MX/MTA: Mail – Sending an email via telnet”
It keep closing down, what do I do? i try to type then it says “closed down by foreign host”
For some reason, the greater than and less than symbols were not showing up in my code. I went ahead and fixed it. You need to have your MAIL FROM and RCPT To email addresses within .
Check the examples above.
Also, make sure to do it fast enough before the MTA closes your session. I usually copy and paste the commands from a text file.
This is not working.yahoo always give status 250 of any RCPT.