SMTP: The mail protocol for the internet


SMTP is used to transfer mail between machines that are continually on the internet, as well as to send mail from a dialup system to another host on the internet. SMTP makes no attempt to authenticate users or systems; the very nature of the network makes such authentication impossible. SMTP transactions occur on port 25. Unlike POP3, commands in SMTP need to be in a particular order. Before any other commands are accepted, the computers need to perform something called handshaking. In this, the originating system (you) says HELO my.fully-resolved.hostname. The other system should give you a similar response. After saying HELO, the user states the origin of the message using
MAIL FROM:sender@host
Secondly, the user states a list of recipients of the message, using
RCPT TO:recipient@host
This command is issued once for each recipient. Then, the DATA command is issued. After this command is issued, all following text is considered to be headers and message body. To terminate a message, a line with just a period is entered. The QUIT command closes the connection.
Here is an example of using SMTP to send a message:
$ telnet mail.foo.bar 25
Trying 192.168.1.1...
Connected to smtp.foo.bar.
Escape character is '^]'.
220 smtp.foo.bar ESMTP Sendmail 8.8.7/8.8.6; Wed, 3 Dec 1997 20:20:43 -0500 (EST)
HELO dialup.foo.bar
250 smtp.foo.bar Hello dialup [192.168.1.2], glad to see you.
MAIL FROM:me@foo.bar
250 me@foo.bar... Sender ok
RCPT TO:user@foo.baz
250 user@foo.baz... Recipient ok
RCPT TO:joerandom@somesite.com
250 joerandom@somesite.com... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
To:user@foo.baz,joerandom@somesite.com
From: me@foo.bar (Pat Gunn)
Subject: Hi there! (test message)

Hi Pat! How are you doing?
I've been bored recently.
See you...
---
Pat Gunn
http://junior.apk.net/~qc
---
.
250 UAA22108 Message accepted for delivery
QUIT
221 smtp.foo.bar closing connection
Connection closed by foreign host.

In this example, I sent an email message with a listed from line as me@foo.bar, to user@foo.baz and to joerandom@somesite.com. It is worthy of note that if I deleted the To: line in the headers of my message (the one AFTER DATA), the recipients of my message would not see who the message is to, and thus would be unaware that my message was sent to more than one person. This is the way that Bcc: works in modern Email software. Common headers that you will want to type include:
SMTP is described in RFC788

Next