E-mail, SMTP & IMAP
There are three major components to e-mail:
- User Agents
- Such as outlook or geary.
- Mail servers
- Mailbox - contains incoming messages for user.
- Mesage Queue - of outgoing messages.
- SMTP Protocol - Between mail server to send email messages.
- The protocol: simple mail transfer protocol (SMTP)
SMTP
The standard for this protocol is RFC 5321.
- Uses TCP on port 25.
- Direct transfer from the sending to receiving server.
- Three phases of transfer:
- Handshaking
- Transer of Messages
- Closure
- Command/Response Interaction (like HTTP):
- Commands: in ASCII.
- Response: Status code and phrase.
Example SMTP Request
SMTP requests are sent as multiple objects, sent in a multi-part message. The message is split based on who is responding.
220 EventMachine SMTP Server
HELO alice
250 Ok EventMachine SMTP Server
MAIL FROM: <sender@example.com>
250 Ok
RCPT TO: <receiver@example.org>
250 Ok
DATA
354 Send it
SUBJECT: Hello
Hi Bob, How's the weather? Alice.
.
250 Message accepted
The message is ended with \r\n.\r\n
. Where \r
is a carriage return and \n
is a newline.
Mail Message Format
SMTP is defined in RFC 531 (like HTTP). Additionally, RFC 822 defines the syntax for e-mail messages (like HTML).
An SMTP message can be split into two parts:
- Header Lines:
To:
From:
Subject:
- Body - Message with ASCII characters only.
Mail Access Protocols
SMTP can send mail but in order to retrieve it and read the contents you must use other protocols:
- SMTP - Delivery and storage of e-mail.
- IMAP (Internet mail access protocol RFC 3501) - Messages stored on server, provides retrieval, deletion & folders of stored messages.
- HTTP - Provides web-based interfaces on top of SMTP & IMAP.