SMTP protocol commands

From Edgar BV Wiki
Revision as of 13:46, 2 March 2007 by Red (talk | contribs) (New page: Press Send and forget about it? Have you ever wondered what happens when you press the Send button? Probalby not, as long as it works. This is exactly the reason why you should wonder. In...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Press Send and forget about it? Have you ever wondered what happens when you press the Send button? Probalby not, as long as it works. This is exactly the reason why you should wonder. In case something doesn't work it's good to know what does not work; anytime, everywhere; it's half the solution.

 When you actually send email the SMT protocol comes into play. SMTP is the Simple Mail Transfer Protocol as (basicaly) defined in RFC 821. Your mail client talks to the SMTP server using this clean procedure to get email from one place to another. 


The flirt Your email program becomes a 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 that it wants to be polite counts. Actually, it does not attempt to be polite but to use later additions to the SMT protocol that have brought about two flavors of HELO.

 EHLO, being the more recent one makes the server advertise all the additional features (such as DSN or 8BITMIME) it supports. Not every server will allow this greeting, but it is requred to accept a play 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 larose.magnet.at ESMTP Sendmail 8.8.6/8.8.6; Sun, 17 Aug 1997 18:13:47 +0200 HELO 501 HELO requires domain address HELO localhost 250 larose.magnet.at Hello localhost [127.0.0.1], pleased to meet you


 (my input is blue, 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 (anyone who knows of another way to make use of an SMTP server can be very happy: she deserves the creative-usage-award) you start with the keywords MAIL FROM:. Following this comes the email address of the sender, as suggested by the from. Continuing our example, we have:

MAIL FROM: email.guide@about.com 250 email.guide@about.com... 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 the About.com support team (only because they have nothing to do and are terribly bored ;-)):

RCPT TO: support@about.com 250 support@about.com... 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 intervalls (for example, every 30 minutes). This behavior depends on the configuration and the server may also deliver the mail instantly. 


The mail Now that the "envelope" is finished comes the data of the email message just as it is. This comprises of the body as well as the header fields. The command to initiate this state where the server will 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 mail:

DATA 354 Enter mail, end with "." on a line by itself Message-ID: <19970817184815.33912@larose.magnet.at> Date: Sun, 17 Aug 1997 18:48:15 +0200 From: Heinz Tschabitscher <email.guide@about.com> To: About.com support <support@about.com> X-Mailer: Mailer X Hi there!

I just told all my readers to try communicating to an SMTP server directly using the email address <support@about.com>.

Have fun!

Heinzl. . 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 "Recipient list suppressed" <nobody@nowhere.no>, if you like that idea and a couple other things. 


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 command QUIT and that's just what we do:

QUIT 221 larose.magnet.at closing connection