Thursday, July 15, 2010

How E-Mail Works


  • The first e-mail message with an "@" sign in the address was sent in 1971.
  • An e-mail system consists of two different servers running on a server machine. You connect to the SMTP (Simple Mail Transfer Protocol) server on its well-known port number 25 to send e-mail to others. And, you connect to the POP3 (Post Office Protocol version 3) server on its well-known port number 110 to fetch the e-mail you may have received.
  • The email program on your computer interacts with the two mail servers at your ISP (Internet Service Provider) to send and fetch email. The interaction is dead simple. You compose your email and submit it to your e-mail program. Your email program connects over the Internet to the mail server, asks you for a username and password (if necessary), and supplies that to the mail server to authenticate you. After successful authentication, your e-mail program's interaction with an SMTP server goes something like this :

    Your e-mail program:helo test
    Mail server:250 mx1.mindspring.com Hello abc.sample.com
    [220.57.69.37], pleased to meet you

    Your e-mail program:mail from: test@sample.com
    Mail server:250 2.1.0 test@sample.com... Sender ok
    Your e-mail program:rcpt to: jsmith@mindspring.com
    Mail server:250 2.1.5 jsmith... Recipient ok
    Your e-mail program:data
    Mail server:354 Enter mail, end with "." on a line by itself
    Your e-mail program:from: test@sample.com
    to:jsmith@mindspring.com
    subject: testing
    John, I am testing...
    .

    Mail server:250 2.0.0 e1NMajH24604 Message accepted
    for delivery

    Your e-mail program:quit
    Mail server:221 2.0.0 mx1.mindspring.com closing connection
    Connection closed by foreign host.

    It is that simple! Really! All e-mail programs do this behind the scenes. If you have "mail.debug" property set to "true", you can see the commands being issued by the Sun JavaMail implementation as they print out on your console.

    Fetching email from a POP3 server works the same way. 

    Notice that the sender and recipients e-mail addresses during interaction with the SMTP server are specified before the "body" of the message. They can be different from what's in the body of the message.

  • RFC822 says that the MIME (Multipurpose Internet Mail Extensions) messages exchanged over the Internet must have header lines and content. All bytes in header and content must be 7-bit US ASCII. Most standard headers are name-value pairs of strings (no binary data). The header lines are separated from the content by a blank line. The RFC specifies standard header fields.
  • RFC822 does not say what the content can contain as long as the content bytes are 7-bit US ASCII. Any non-US-ASCII headers and content need to be encoded into the 7-bit US-ASCII (mail-safe) format using base64 and quoted-printable schemes. The MIME RFCs 2045, 2046 and 2047 specify how to do this. Each MIME content will have a content type, structured body parts and a set of encoding schemes to encode data into mail-safe characters.

No comments:

Post a Comment