Email: SMTP, Message Format, POP3, and IMAP
SMTP (Simple Mail Transfer Protocol)
An email system has user agents, mail servers, and SMTP. Outlook, Apple Mail, and Gmail are examples of user agents. When Alice sends mail, her agent submits it to a mail server's outgoing queue. Bob's agent later retrieves the stored message from his mail server.
SMTP is an application-layer mail-transfer protocol using TCP's reliable service. Port 25 is used for server-to-server transfer.
SMTP transfers messages through commands and replies. The following overview also includes fields shown to mail readers:
| Command / field | Description |
|---|---|
| HELO | Introduce the client |
| AUTH | Authenticate |
| MAIL FROM | Envelope sender |
| RCPT TO | Envelope recipient |
| DATA | Begin message data |
| FROM | Displayed sender field |
| TO | Displayed recipient field |
| SUBJECT | Message subject |
| QUIT | Close the session |
| Reply | Meaning |
|---|---|
| 220 | Service ready |
| 250 | Requested action completed |
| 235 | Authentication succeeded |
| 221 | Closing the transmission channel |
| 354 | Ready for message data |
| 500 | Command error |
| 550 | Requested action unavailable |
The Envelope and the Message Are Different
MAIL FROM and RCPT TO belong to the SMTP envelope. From, To, and Subject are message headers transferred during DATA, not separate SMTP commands. The envelope determines mailbox delivery; display fields help readers identify the apparent sender and subject. They can differ, and a displayed From field alone does not prove identity.
354 marks readiness for data. A line containing only a period normally ends that phase, with special handling for content lines beginning with a period. 221 closes the transmission channel. Understand these boundaries without connecting to a real mail service.
Route a mail envelope, then retrieve the message
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Accessing Stored Mail
Reading stored messages uses an access protocol: POP3 (Post Office Protocol version 3), IMAP (Internet Mail Access Protocol), or HTTP.
SMTP mainly pushes mail. POP3 offers simpler download access; deletion after download depends on policy. IMAP manipulates server-side mailboxes, folders, and message state, supporting multiple devices. Webmail browsers use HTTP/HTTPS to a web service, whose backend can interact with the mail system.
A message separates headers and body with an empty line. Python's email library can parse it. Do not treat every colon as an arbitrary splitting point or mistake one header line for a complete SMTP conversation.
KNOWLEDGE QUIZ
Parse a synthetic message with Python
Parse the message with From: [email protected], To: [email protected], Subject: Meeting, an empty line, and body Meet at 10. Use email.parser.Parser with policy.default. Print To, Subject, and the stripped body on separate lines. Explain whether these fields prove the SMTP envelope recipient or authenticated sender. No mail is sent.