Andrew McDonough

Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.


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 Trying… Connected to Escape character is ’^]‘. 220 ESMTP 8si10731759ewy.109

Most servers like you to say helo first: helo 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 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 250 2.1.5 OK 8si10731759ewy.109

Now for the message, enter the command data. You should get a reply with code 354: data 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: quit 221 2.0.0 closing connection 8si10778608ewy.61 Connection closed by foreign host.

Andrew McDonough

Andrew McDonough is a consultant CTO and software developer, currently based between Berlin and London.

Follow Andrew on Twitter or Connect on LinkedIn