SMTP Inside Out

How internet email works

Neon envelope symbol in one way street at night
Cultura Exclusive/J J D/Getty Images

Have you ever wondered what happens when you press the Send button in your email program? Probably not, I guess — as long as it works. This is exactly the reason why you should wonder, though. In case something doesn't work it's good to know what does not work. Usually, that's half the solution.

When you send email SMTP comes into play. SMTP is short for Simple Mail Transfer Protocol as defined in RFC 5321: Simple Mail Transfer Protocol.

Your mail client talks to the SMTP server using this clean and simple procedure to get email from one place to another.

The Flirt

Your email program becomes an SMTP client, connects to port 25 of your mail server (usually the SMTP port) and — says EHLO. Computers, in the end, are only human and what counts is that it wants to be polite. Actually, it does not attempt to be polite but to use later additions to SMTP that have brought about two flavors of the later HELO command (SMTP command generally consist of four characters).

Two Flavors of HELO

EHLO, being the more recent one makes the server advertise all the additional features (such as delivery status notification or the ability to transport messages that contain other than the safe ASCII characters) it supports.

Not every server will allow this greeting, but it is required to accept a plain HELO which naturally assumes that no additional features are present.

Both hello commands do require the client to specify its domain after the **LO, however. In practice, this looks something like:

220 ESMTP Server
501 HELO requires domain address
HELO localhost
250 Hello localhost [], pleased to meet you

(My input is in italics, the servers output is black; lines beginning with a 5 indicate an error.)

The Sender

The remainder of the protocol really deserves the attribute simple. If you want to send an email, you start with the keywords MAIL FROM:. Following this comes the email address of the sender, as suggested by the from. Don't forget to put brackets around the address, though (like <>). Continuing our example, we have:

250 Sender ok

The recipient

After the server has accepted the sender's address, the client can give the address of the recipient. The command for this action, RCPT TO: again is rather suggestive. I want to send mail to myself:

250 Recipient ok (will queue)

That the server will queue means just that: it will save the mail locally and send it together with all the other queued mail in intervals (for example, every 30 minutes). This behavior depends on the configuration and the server may also deliver the mail instantly.

We're almost done. What's still missing, though, is the important part: the actual message.

The Message

Now that the "envelope" is finished, the data of the email message just as it is can follow. This "data" consists of the email's body as well as the header fields.

The command to initiate the state that makes the server accept the message is DATA. Following this are all the header fields of the email message and then the body, both making up for just one big block of text (or data). To tell the server that the input is finished a dot on a line by itself is used (\r\n.\r\n).

So I send my message:

354 Enter mail, end with "." on a line by itself
Message-ID: <kllsd0817184815.33912@larose>
Date: Sun, 17 Aug 1997 18:48:15 +0200
From: Heinz Tschabitscher <>
To: Heinz Tschabitscher <>
Subject: For the Summarize-Proust Contest

Off to Swan's World!

250 SAA19153 Message accepted for delivery

Yes, this means that you can state a name completely different from the one the email goes to in the To: field. For example, you can use "Recipient list suppressed" <>.

The End

You can now send as many emails as you wish repeating the steps from MAIL FROM: to .. If you're done with that, you may quit the server with the QUIT command and that's just what we do:

221 Goodbye

How Can I do This?

The non-trivial solution is to telnet to your outgoing mail server (you can find its address in your email client's account settings) on port 25.

  • Open a command prompt.
  • Type "telnet <mail server> 25".
  • Talk to the server using SMTP.

The easier way is to use this Java applet, which tries to imitate the SMTP protocol and guides you through the dialog.

More From Us