01.06.2015 Views

SMTP Overview

SMTP Overview

SMTP Overview

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Simple Mail Transfer Protocol<br />

<strong>Overview</strong><br />

<strong>SMTP</strong> is the Internet protocol used to transfer electronic mail between computers, much like HTTP is the<br />

Internet protocol used to transfer web pages between computers. Like HTTP, there has been more than one<br />

generation of <strong>SMTP</strong>; the second generation is called E<strong>SMTP</strong> (for Extended <strong>SMTP</strong>), but the differences are not<br />

important for this introduction.<br />

This attempts to be a quick overview of <strong>SMTP</strong> and related concepts, explaining enough of how it works so that<br />

the reader can follow reasonable technical discussions.<br />

In <strong>SMTP</strong> (and in the rest of this discussion), the client is the computer that is sending email, and the server is<br />

the computer that is receiving it. Thus we say <strong>SMTP</strong> clients (or <strong>SMTP</strong> senders) send email to <strong>SMTP</strong> servers,<br />

although the machines involved may both be servers in the general sense; for example an ISP's mail server<br />

sending email to the <strong>SMTP</strong> servers for ilstu.edu.<br />

The envelope versus the letter<br />

Just like physical letters, <strong>SMTP</strong> email has two different sets of address information: the envelope headers, like<br />

the addresses on the outside of an envelope, which are used by mail transport software to route and deliver the<br />

email, and the normal headers, which are part of the mail message and which are only read and interpreted by<br />

the user and his software, just like the address attached to a salutation at the start of a physical letter. Unlike the<br />

post office, <strong>SMTP</strong> usually throws away most of the envelope before it hands the message to the user, so many<br />

users are not aware of the envelope headers.<br />

In fact, <strong>SMTP</strong> never looks at the message headers at all; as far as <strong>SMTP</strong> is concerned, the email message<br />

(headers and all) is just one big blob that it shuttles around. Many <strong>SMTP</strong> clients are perfectly happy to deliver<br />

email with badly broken or entirely nonexistent message headers.<br />

The <strong>SMTP</strong> protocol<br />

Like many Internet protocols, <strong>SMTP</strong> operates by sending lines of text back and forth between the client and the<br />

server. The client sends commands and eventually the email message, and the server sends back responses to<br />

tell the client if the server accepted the command or if something went wrong.<br />

Server responses always come in a special format: three digits, a space (or a dash), and then some free-format<br />

text (in error messages, this is usually intended for users to read; otherwise it is generally just noise). If there is<br />

a dash after the third digit instead of a space, further lines of response follow; otherwise, this is the last line. The<br />

only really important thing about the response is the first digit, like so:<br />

Code<br />

2xx<br />

4xx<br />

5xx<br />

Meaning<br />

everything is fine, go on<br />

temporary problem, try again later<br />

permanent error, give up<br />

Errors can happen at any time, so at any response a server can send a temporary or a permanent error instead<br />

of the go ahead indication the client was expecting. A proper client must be able to cope with this, retrying


temporary failures (but not too soon or too often) and giving up gracefully on permanent failures. (Tragically,<br />

there are improper clients out there in the world.)<br />

A <strong>SMTP</strong> conversation between the client and the server goes in stages, each one initiated by the client doing<br />

something. A typical conversation will look like:<br />

Client does:<br />

Connects to the server<br />

220 Helo there<br />

Server normally responds with:<br />

HELO client-hostname<br />

250 Pleased to meet you<br />

MAIL FROM:<br />

250 OK<br />

RCPT TO:<br />

(May be repeated)<br />

250 OK<br />

DATA<br />

354 Start mail input; end with .<br />

Sends the actual email message<br />

(Nothing, it's waiting for the . that ends the message)<br />

. 250 OK, accepted for delivery<br />

At this point the email message has been sent. The client can now disconnect with a QUIT command, or it can<br />

send another email message by starting with the MAIL FROM step again (optionally sending a RSET command<br />

first).<br />

The sender address is the email address that will receive email about delivery problems (mailing lists change<br />

this but not the From: email header so that they, and not the people sending to them, get messages about<br />

delivery problems). A special null sender address (MAIL FROM:) is used to signal that no one cares and no<br />

bounce notifications should be sent. Null senders are used when sending bounce messages themselves, and<br />

sometimes at other times.<br />

There can be multiple recipients of the same message on the same computer. So that the actual email message<br />

only has to be transfered once (saving bandwidth), there can be several RCPT TOs for a message. (There has to<br />

be at least one, just like there has to be a MAIL FROM.) The client has to keep track of which recipient addresses<br />

have problems, if any, and retry them later if necessary.<br />

The envelope headers are the MAIL FROM and RCPT TO parts of the <strong>SMTP</strong> conversation. The envelope sender is<br />

the MAIL FROM address, and the envelope recipients are the RCPT TO addresses.<br />

The client-hostname, the sender address, and the recipient addresses should all be fully qualified. A fully<br />

qualified host or domain name is one that anyone on the Internet could use to look up information, not a<br />

shortened name useful only on machines inside an organization; for example, server.example.com instead of<br />

just server. A fully qualified email address is an email address with a fully qualified host or domain name, not<br />

just an email login; for example, MAIL FROM: instead of MAIL<br />

FROM: or MAIL FROM:. If the host or domain name is left off an email<br />

address, the <strong>SMTP</strong> server usually has no choice but to interpret it as an address on itself.


Email routing, or welcome to DNS<br />

All of this is very well and good, but it doesn't tell us how a client machine with email to send to<br />

user@ilstu.edu decides which <strong>SMTP</strong> server to deliver it to. That is decided by looking various pieces of<br />

information up in the Domain Name System, DNS, which is another Internet protocol and system.<br />

DNS exists to give out various sorts of information about names; you give it a name and what type of<br />

information you want, and it tries to give you back an answer. For our purposes (and simplifying a bit), there<br />

are three interesting types of information, conventionally called record types:<br />

NS records for a domain, which tell you what hostnames can give you further information about that<br />

domain and names inside that domain, such as MX records or A records.<br />

MX records for a name, which tell you what hostnames should accept <strong>SMTP</strong> email for user@name, and<br />

which order you should try them in.<br />

A records for a hostname, which give you the IP addresses associated with the host.<br />

Reduced to its simplest form, a <strong>SMTP</strong> client with email to send to user@example.com looks up NS records<br />

until it finds the nameservers for example.com, then asks them for the MX record for example.com, and finally<br />

asks for A records to determine the IP addresses of the names in the MX record. If a name has no MX record<br />

but does have an A record, email is delivered straight to the IP addresses listed.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!