Wednesday, February 13, 2013

How E-mail Works !?


The SMTP Server

Whenever you send a piece of e-mail, your e-mail client interacts with the SMTP server to handle the sending. The SMTP server on your host may have conversations with other SMTP servers to deliver the e-mail.
Let's assume that I want to send a piece of e-mail. My e-mail ID is brain, and I have my account on email365.org. I want to send e-mail to juantrinh@yahoo.com. I am using a stand-alone e-mail client like Outlook Express.
When I set up my account at email365.org, I told Outlook Express the name of the mail server -- mail.email365.org. When I compose a message and press the Send button, here's what happens:
  1. Outlook Express connects to the SMTP server at mail.email365.org using port 25.
  2. Outlook Express has a conversation with the SMTP server, telling the SMTP server the address of the sender and the address of the recipient, as well as the body of the message.
  3. The SMTP server takes the "to" address (juantrinh@yahoo.com) and breaks it into two parts: the recipient name (juantrinh) and the domain name (yahoo.com). If the "to" address had been another user at email365.org, the SMTP server would simply hand the message to the POP3 server for email365.org (using a little program called the delivery agent). Since the recipient is at another domain, SMTP needs to communicate with that domain.
  4. The SMTP server has a conversation with a Domain Name Server, or DNS. It says, "Can you give me the IP address of the SMTP server for yahoo.com?" The DNS replies with the one or more IP addresses for the SMTP server(s) that Yahoo operates.
  5. The SMTP server at email365.org connects with the SMTP server at Yahoo using port 25. It has the same simple text conversation that my e-mail client had with the SMTP server for Email365.org, and gives the message to the Yahoo server. The Yahoo server recognizes that the domain name for juantrinh is at Yahoo, so it hands the message to Yahoo's POP3 server, which puts the message in juantrinh's mailbox.
If, for some reason, the SMTP server at Email365.org cannot connect with the SMTP server at Yahoo, then the message goes into a queue. The SMTP server on most machines uses a program called sendmail to do the actual sending, so this queue is called the sendmail queue. Sendmail will periodically try to resend the messages in its queue. For example, it might retry every 15 minutes. After four hours, it will usually send you a piece of mail that tells you there is some sort of problem. After five days, most sendmail configurations give up and return the mail to you undelivered.
The SMTP server understands very simple text commands like HELO, MAIL, RCPT and DATA. The most common commands are:
  • HELO - introduce yourself
  • EHLO - introduce yourself and request extended mode
  • MAIL FROM: - specify the sender
  • RCPT TO: - specify the recipient
  • DATA - specify the body of the message (To, From and Subject should be the first three lines.)
  • RSET - reset
  • QUIT - quit the session
  • HELP - get help on commands
  • VRFY - verify an address
  • EXPN - expand an address
  • VERB - verbose