Three major components:
- User agent
- Agent through which the user accesses and sends email
- Mail server
- Has a mailbox containing incoming messages
- Has a message queue of outgoing messages to send
- SMTP
- Protocol used to exchange information between mail servers
- Mail servers run both the client and server
Simple Mail Transfer Protocol (SMTP)
The standard protocol used to transfer email between servers.
Basic operation:
- A uses a user agent (UA) to compose message
- A’s UA sends the message to their mail server and places it in a message queue
- Called a email submission
- A’s mail server’s SMTP client opens a TCP connection with B’s mail server’s SMTP server
- If multiple messages need to be sent, they are sent over a persistent TCP connection
- B’s mail server places the message in B’s client
- B uses his UA to read the message
SMTP uses telenet connection and runs on port 25 by default.
Sample telenet interaction:
- TCP connection established; server sends three digit reply code (probably
220) and information about the server (host name, server name/version, date/time etc.) - Client sends
HELO client_host_namemessage; server responds (with250if valid) - Client sends
MAIL FROM: <user@client_host_name>message; server confirms validity - Client sends
RCPT TO: <user@server_host_name>message; server confirms validity - Client sends
DATAmessage; server responds with delimiter used to close the email - Client sends body content, ending it with the specified delimiter
- Body content typically restricted to 7-bit ASCII
- Server responds with status message
- Client sends
QUITmessage
Mail message format:
From: user@client_host_name
To: user@server_host_name
Subject: subject_text
[BLANK LINE]
message_body
The receiving server appends a Received: header line to the top of the message as a record of the mail servers the email passed through.
Multipurpose Internet Mail Extension (MIME)
For non-ASCII data, MIME is used. It specifies the type of content (e.g. jpeg, mp3) and the method in which it is encoded. For example:
...
Subject: subject_text
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: image/jpeg
[BLANK LINE]
base64_encoded data
In base64 encoding, every three octets (24 bits) are divided into four bytes of 6 bits each - enough to fit into an ASCII character. The characters A-Za-z0-9+/ is used, with A corresponding to 0 and / to 63. = is used as padding.
SMTP and Mail Access Protocols
Access protocols are used for communication between the receiver’s mail server and user agent. Two mail protocols are:
- POP3 (Post Office Protocol):
- After authorization, the message is simply downloaded
- IMAP (Internet Mail Access Protocol):
- More features
- Allows messages stored on the server to be manipulated
Web-based email is another alternative; the user agent uses HTTP to communicate with its remote mailbox.
POP3
TCP telenet connection running on port 110.
During the authorization phase, the client sends two commands:
user usernamepass password
After each command is sent, the server responds with either +OK or -ERR.
During the transaction phase, the client can send:
list: list message numbersretr mail_num: retrieve message by that numberdele mail_num: delete message with that number
IMAP
IMAP:
- Keeps all messages in the server
- Allows the user to organize messages in folders
- Keeps state across sessions
- ALlows the user to obtain components of messages instead of the entire message
Domain Name System (DNS)
DNS is:
- a directory service
- a distributed database implemented in a hierarchy of DNS servers
- an application-layer protocol (UDP on port 53)
Some DNS services:
- Hostname to IP address translation
- On Linux, this can be done using the command
gethostbyname
- On Linux, this can be done using the command
- Host aliasing
- Canonical (
CNAMErecords) and alias names (e.g.www.)
- Canonical (
- Mail server aliasing (
MXrecords) - Load distribution
- Reply to DNS request can return a list of IP addresses. With DNS rotation, the list can rotate, and as clients typically pick the first address, the load can be distributed to multiple servers
DNS is not centralized:
- Acts as a single point of failure
- Traffic volume too large
- Latency: will be far away from most hosts
- Maintenance almost impossible
Hierarchy
DNS is composted of three main levels of DNS servers:
- Root DNS servers
- Top-level domain (TLD) servers
com,orgetc.
- Authoritative DNS servers
- May be provided by organization or service provider
- Non-authoritative DNS servers will cache responses from the latter, so may not be accurate
If a client wants the IP address for www.google.com, to a first approximation, it will:
- Query the root server for the
comDNS server - Query the
comDNS server to get thegoogle.comDNS server - Query the
google.comDNS server for the IP address forwww.google.com
There are 13 root name servers worldwide (although each is a cluster of replicated servers).
Local name servers do not belong to the hierarchy, but are central to the DNS architecture. Each ISP has provides one and acts as the default name server.
Query Types and Caching
If a client wants the IP address for www.google.com through an iterated query:
- The client sends a query to the local DNS server
- The local DNS server sends a query to the root DNS server for the IP address of the
comDNS server - The local DNS server sends a query to the
comDNS server for the IP address of the authoritative DNS server forgoogle.comhost - The local DNS server sends a query to the authoritative DNS server for the
google.comhost for the IP address ofwww.google.com - The local DNS forwards the reply back to the client
A recursive query puts the burden of name resolution to the contacted name server:
- The client sends a query to the local DNS server
- The local DNS server sends a query to the root DNS server for the IP address of
www.google.com - The root DNS server sends a query to the
comDNS server for the IP address ofwww.google.com - The
comDNS server sends a query to the authoritative DNS server for thegoogle.comhost for the IP address ofwww.google.com - The response recursive through the stack back to the client
Both queries require 8 messages. Hence, caching is used:
- Once any name server learns a mapping, it caches it
- TTL ensures cache entries expire
Hence, root name servers are usually not consulted.
DNS records
Each resource record stores the name, value, type, ttl and class (although that is always IN (internet)).
Some types values:
A:nameis hostname;valueis the IP address- IPv6 uses the
typeAAAAas the IPv6 addresses use four times as many bits
- IPv6 uses the
NS:nameis the domain,valueis the hostname of the authoritative name server for the domainCNAME:nameis the alias name for the canonical name stored invalueMX:valueis the canonical name of the mail server associated with the alias name
DNS Messages
Both query and rely messages use the same message format:
| 16 bits | 16 bits |
| Identification | Flags |
| Num. questions | Num. answer RPs |
| Num. authority RPs | Num. additional RPs |
| Questions (variable num.) |
| Answers (variable num. RRs) |
| Authority (variable num. RRs) |
| Additional info (variable num. RRs) |
The query and reply to the corresponding query have the same identification number.
The flags indicate;
- If the message is a query (
0) or reply (1) - If the query is recursive or not
- If a reply, it will indicate if the server supports it
The additional fields:
- Questions (
(Name, Type))- Reply will repeat these
- Answers (
(Type, Value, TTL)) - Authority: records for authoritative servers
- Additional information (e.g. IP address of authoritative DNS server)
Adding New Records
Example: registering a domain name at a registrar:
- Need to provide registrar with host names and IP addresses of primary/secondary authoritative DNS servers
- Registrar inserts two RRs into the TLD server for each authoritative name server
(host_name, authoritative_DNS_server_host_name, NS)(authoritative_DNS_server_host_name, authoritative_DNS_server_IP_address, A)
- Go to the authoritative name server and insert records pointing to your server there