SMTP (Port 25): handles outgoing mail
POP3/IMAP (Port 110/143): handles incoming mail
Let's have scenario: John Doe at hotmail.com sends email to Laura Johnson at gmail.com. John Doe uses Outlook to send an email. Laura uses web interface for gmail.com to access the email from John.
(Outlook, web interface are the front end for the users. Those are just the GUI interface)
John uses Outlook--> sends email from Hotmail.com account to Laura Johnson at Gmail.com account--> Laura checks email at www.gmail.com
1. Outlook connects to SMTP server at hotmail.com using Port 25
John writes an email to Laura
From: John.Doe@hotmail.com
To: Laura.Johnson@gmail.com
Subject: Hi Laura
Body: Hi Laura, How are you? What's your plan for this weekend? Let's go to the state fair at Dallas.
2. SMTP server at hotmail.com reads "TO" field and breaks it into two parts e.g Laura.Johnson@gmail.com is broken into "Laura.Johnson" and "gmail.com"
3. SMTP server at hotmail.com queries to DNS server; Who is SMTP server at gmail.com?
DNS server looks into MX records and replies back with one or more SMTP servers at gmail.com
4. SMTP server at hotmail.com connects to one of the SMTP server at gmail.com and handles the message. SENDMAIL and POSTFIX are the most popular MTA (Mail Transfer Agent) to deliver mail from one SMTP server to another another SMTP server. My preference is POSTFIX as it's free, easy, secure, customizable and popular too.
5. SMTP server at gmail.com recognizes that "Laura.Johnson" is the user at gmail.com and it handover the message to gmail POP3/IMAP server which puts the message in the Laura.Johnson's INBOX.
6. Laura logs in to www.gmail.com and checks her email.
It's that easy. Remember, we didn't talk about handling the junk emails.
It goes little bit complex for handling the junk emails. Please google about that if you want to know more...
Extra Treat:
SMTP commands:
HELO
EHLO
MAIL FROM
RCPT TO
DATA
RESET
QUIT
HELP
VRFY
EXPN
VERB
POP3 commands:
USER
PASS
QUIT
LIST
RETR
DELE
TOP