http://www.faqs.org/rfcs/rfc821.html , http://www.faqs.org/rfcs/rfc2821.html .
Most of this was written according to 821. I then updated it according to
2821.
Also see RFC2822 about message data contents.
SENDER -> RECEIVER CONVERSATION (\r\n line terminators).
Commands, replies, hostnames insensitive; LOCALPARTS ARE case sensitive!
HELO mhost helo clienthost.domain.com
MAIL command mail from:
RCPT command rcpt to:
RCPT command rcpt to:
DATA data
blah
blah quit
.
QUIT command (Both sides wait for Ack form other side before quitting)
(can't "quit" prematurely. Use 'RSET' for that.)
MAIL indicates an addr to receive error messages/warnings.
(Aka "originator" and is copied into "Return-Path:" upon final delivery.)
HELO hostname is a real "known" fqdn name or an addr. Can be followed by
identitying info.
The SMTP Envelope args may not contain a comment (they SHOULD use <>).
N.b. UPDATE!!! Per rfc2821, source routes are obsolete. Just strip them.
MAIL and RCPT addresses are SINGLE addresses, but may contain a source route
list of hosts (in sequence) to deliver to the terminating mailbox (on the last
host). list like
<@ONE,@TWO:JOE@THREE>
[ For reverse source route, this says
Current sender host is "one", orig sender was joe@three on host TWO.
(Called a "source route"). First host in reverse path is sending host;
First host in forward path is receiving host.
BOUNCE MESSAGES have From addr of "<>" and no source route.
(I've verified that it is the real sender that does these changes.
SMTP RECEIVER INTERPRETS/TRANSLATES (=> is a translation).
"\r\n.\r\n" = EOD
"\r\n" => "\n"
"^.." => "^.".
So, MUA's c/^./../, network sees "\r\n"'s and "^.."'s.
If you use telnet instead of MUA, it will do \n => \r\n, but will not do
the ^. stuff.
Sendmail receives EOD with "\r\n.\r\n" and adds the firs "\n" to the
message. Therefore, if mail is received by Sendmail, the received
message WILL end with \n.
Headers (not the SMTP commands) are called "memo/message/data header items".
SMTP doesn't have rule for these, but I see that continuation lines begin
with \t. Requirement is AT LEAST one LWSP, linear white-space.
There can definitely be duplicates.
2 commands can be given any time during conversation.
Update per rfc2821!!! No source routes in these replies.
VRFY and EXPN "SHOULD" be supported, and for SMTPE must be listed as
a service extension.
VRFY command vrfy username (usernames are "at least" local users)
Server replies with optional full name + mailbox of user.
request:
vrfy Fred
OR
vrfy fred@admc.com
with reply:
Fred Smith
OR
EXPN command mailing_list
expn Example-People
Server replies with optional full name list + all mailboxes. One per line.
RELAYING
Server modes the self element from head of TO host list (if that element
is there) and always adds addr (as known by next destination) to head of
FROM host list.
Update per rfc2821. Don't set the source paths.
DATA
7-bit 128 ASCII characters. Any special chars, but 7-bit.
Upon every receipt, a timestamp is added at top of message data.
sending host, receiving host (me), date & time
Final SMTP recipient adds a reverse-path line at top of message data.
MAIL revers-path info.
Update per rfc2821. Return-Path: EXACT ARG TO "MAIL" COMMAND
DELIVERED MESSAGE BODY
Final receipt reverse path line. Return-Path:
Time stamp lines. Received:
Data header... Date:
Body From:...
DELIVERY TO SOME RECIPIENTS
Server replies "success", but sends bounce(s) to notify sender about all
failed recipients.
OTHER SMTP CLIENT COMMANDS
RSET (reset) [STILL NEED TO QUIT AFTER THIS!]
These can be given at any time during conversation.
HELP [command]
NOOP
SERVER REPLIES
All reply lines start with status code.
Terminating lines are code + ' '< like "123 ".
Non-terminating lines begin with status code plus "-". Like "123-".
###################################################################3
RFC2821 EXTENSIONS
EHLO. A server that supports EHLO is an ESMTP server.
EHLO keywords
EHLO (server replies with list of supported extensions. 1 ea. line).
Keywords beginning with X are home-grown/non-approved options.
8BITMIME
MUAs: Sources and targets of email.
MTAs: Transmitters/transmittees.
Optional args to MAIL and RCPT commands (based on the extension).
RCPT may use arg "postmaster" with no domain. Other addresses need
absolute domains.
Mailing lists. When delivering to list recipients, change the MAIL addr
to the list adminstrator, but leave the message headers alone.
Aliases. Receiving mailer replaces alias addr in envelope (i.e, RCPT)
with each recipient in turn, leaving message body alone.
Lists. Recipient mailer replaces list addr in envelope (i.e, RCPT)
with all of expanded addreses, and return addr is changed to list adminer.
Note that "envelope" is not visible directly to real recipient, but
only to the receiving MTA. E.g., RCPT fields are only visible during
message transmission (but receiving MTA could write it all into message :(.)
QUITY may now be issued at any time.
Mail From. From envelope addr should be the "sender mailbox".
If needed to avoid a loop, it may be null.
JavaMail, however, always sets "Return-path:", regardless of whether
"From " or "Reply-to:" are set. (Even if From is set blank by setting
it to "<>").
Received: timestamp line formats
FROM: EHLO hostname + ip addr
ID? optional @
FOR deprecated list of RCPT
Must implement minimum timout values (specified in the rfc).
Content headers are ALWAYS in US ASCII!