SMTP is the standard protocol used to deliver email.

How to send email via SMTP

In this example, I will demonstrate how to send an email to the email address

Identifying the MX record for the domain

First, find the MX record for the domain you wish to send email to:

$ dig -t mx

The reply should contain an ANSWER SECTION. I use Google for my email, so I get:

;; ANSWER SECTION:	86400	IN	MX	5	86400	IN	MX	10	86400	IN	MX	1	86400	IN	MX	5

This shows there are four potential mail servers you can use to deliver email to this user. The final column in this reply is the name of the server and the penultimate column is the priority. Identify the one with the highest priority, in this case 1, which gives the mail server

Connecting to the mail server

You now need to connect to the mail server identified above on port 25.

$ telnet 25
Connected to
Escape character is '^]'.
220 ESMTP 8si10731759ewy.109

Most servers like you to say helo first:


If the mail server likes this, it should give a reply with code 250. All replies with a code 250 are good.

250 at your service

Now identify who the mail is from sing the mail from command. Make sure you enclose the email address in angle brackets.

mail from:<>
250 2.1.0 OK 8si10731759ewy.10

And who you are trying to send mail to using the rcpt to command. If you are trying to mail multiple people on this mail server, you can enter several of these:

rcpt to:<>
250 2.1.5 OK 8si10731759ewy.109

Now for the message, enter the command data. You should get a reply with code 354:

354  Go ahead 8si10731759ewy.109

You can enter multiple lines. When you are finished, place a full stop (period) on a line by itself. If you want the email to have a subject, put this on the first line preceded by the word Subject and a colon:

Subject: A Test Message
Here is a message
on multiple lines

And again, you should get a positive reply.

250 2.0.0 OK 1244025655 8si10731759ewy.109

That's it. The email has been sucessfully sent. You can now quit the session by using the quit command:

221 2.0.0 closing connection 8si10778608ewy.61
Connection closed by foreign host.
smtp.txt · Last modified: 2009/06/03 10:59 by andrew
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki