Email
• SMTP - Simple Mail Transfer Protocol
– RFC 821
• POP - Post Office Protocol
– RFC 1939
• Also:
– RFC 822 Standard for the Format of ARPA
Internet Text Messages
– RFCs 1521, 1522 Mime
Netprog: Email Protocols
1
Terminology
• User Agent (UA): end-user mail
program
• Message Transfer Agent (MTA):
responsible for communicating with
remote hosts and transmitting/receiving
email (both a client and server).
• Mail Exchanger: host that takes care of
email for a domain.
Netprog: Email Protocols
2
SMTP
Used to exchange mail messages between mail
servers (Message Transfer Agents).
MTA
SMTP
MTA
SMTP
MTA
File
System
SMTP
UA
UA
Netprog: Email Protocols
3
SMTP Protocol
•
•
•
•
SMTP sender is the client
SMTP receiver is the server.
The communication use NVT ASCII.
Alternating dialogue:
– client sends command and server responds with
command status message.
– Order of the commands is important!
– Status messages include ascii encoded numeric
status code (like 250, 220) and text string.
Netprog: Email Protocols
4
SMTP Commands
• HELO - identifies sender
• MAIL FROM: - starts a mail transaction and
identifies the mail originator
• RCPT TO: - identifies individual recipient. There
may be multiple RCPT TO: commands.
• DATA - sender ready to transmit a series of lines of
text, each ends with \r\n. A line containing only a
period ‘.’ indicates the end of the data.
Netprog: Email Protocols
5
Data Format
• ASCII only- must convert binary to an
ASCII representation to send via email.
• What if we want to send a line
containing only a period?
– Sender prepends a period to any line
staring with a period (in the message).
– Receiver strips the leading period in any
line that starts with a period and has more
stuff.
Netprog: Email Protocols
6
Leading Period
DATA
354 Start mail input; end with <CRLF>.<CRLF>
this message is a test of SMTP
..
..foo
..
.
250 2.6.0 <c2b1c1a0-3951-4fd6-b6fb-675c0ee4a0dd>
Queued mail for delivery
Resulting Message:
this message is a test of SMTP
.
.foo
.
Netprog: Email Protocols
7
Typical Exchange
[email protected] % telnet hub0.engr.sc.edu 25
Trying 129.252.21.22...
Connected to hub0.engr.sc.edu.
Escape character is '^]'.
220 HUB0.engr.sc.edu Microsoft ESMTP MAIL Service ready at Sat, 17 Nov
2007 20:18:49 -0500
HELO
250 HUB0.engr.sc.edu Hello [129.252.130.106]
MAIL from:<[email protected]>
250 2.1.0 Sender OK
RCPT to:<[email protected]>
250 2.1.5 Recipient OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Subject:test
from:[email protected]
to:[email protected]
this is a test mail
.
250 2.6.0 <c2b1c1a0-3951-4fd6-b6fb-675c0ee4a0dd> Queued mail for
delivery
Netprog: Email Protocols
8
Other SMTP Commands
VRFY - confirm that a name is a valid recipient.
S: VRFY Smith
R: 250 Fred Smith <[email protected]>
EXPN - expand an alias (group email address).
S:
R:
R:
R:
R:
R:
R:
EXPN Example-People
250-Jon Postel <[email protected]>
250-Fred Fonebone <[email protected]>
250-Sam Q. Smith <[email protected]>
250-Quincy Smith <@USC-ISIF.ARPA:[email protected]>
250-<[email protected]>
250 <[email protected]>
TURN - switch roles (sender <=> receiver).
Netprog: Email Protocols
9
more Commands
SOML - Send Or Mail
if recipient is logged in, display message on
terminal, otherwise email.
SAML - Send and Mail
NOOP - send back a positive reply code.
RSET - abort current transaction.
Netprog: Email Protocols
10
Envelopes, Headers, and
Body
• Envelopes are used by MTAs for delivery
– Specified by MAIL and RCPT commands
• MAIL from:<[email protected]>
• RCPT to:<[email protected]>
• Headers are used by user agents
– RFC 822 specifies header format
– Each header field contains a name, a colon, and field value
• Body is content of message from sending user to
receiving user
– When transferred using DATA command, headers are sent
first, followed by a blank line, followed by body
Netprog: Email Protocols
11
Mail Headers
• Email messages contain many headers,
some headers are created by the UA, some
are automatically added by the MTA.
• Every MTA adds (at least) a “Received:”
header.
• Some of the headers are read by (parsed)
intermediate MTAs, but the content is ignored
and passed on transparently.
Netprog: Email Protocols
12
Transmission of a Mail
• User agent takes body, adds some headers,
and passes to MTA
• MTA adds some headers, adds envelope, and
sends to another MTA
Netprog: Email Protocols
13
Transmission of a mail to [email protected]
• MTA asks the DNS for CNAME records for cs.vn.nl
and the response says non exist.
• MTA asks the DNS for MX records for cs.vn.nl and
get one record zephyr.cs.vn.nl
Portion of a possible DNS database
zephyr.cs.vu.nl.
top.cs.vu.nl.
86400 IN A
86400 IN A
130.37.16.112
130.37.16.6
Netprog: Email Protocols
14
Transmission of a mail to [email protected]
• MTA asks the DNS for an A record for zephyr.cs.vn.nl and
get back the value of 130.37.16.112.
• An SMTP connection is initiated to 130.37.16.112 and the
mail is sent.
Portion of a possible DNS database
zephyr.cs.vu.nl.
top.cs.vu.nl.
86400 IN A
86400 IN A
130.37.16.112
130.37.16.6
Netprog: Email Protocols
15
Improvements on SMTP
• Envelope changes: Extended SMTP
• Header changes: Non-ASCII characters
• Body changes: Multipurpose Internet
Mail Extensions (MIME)
Netprog: Email Protocols
16
Extended SMTP
• Framework for adding extensions to SMTP
• Client wishing to use new features can use
EHLO, instead of HELO, to initiate session
• Server lists extended commands in the 250
reply to EHLO command
Netprog: Email Protocols
17
Non-ASCII Characters
• Allow additional characters in sender and
receiver names and in subject
• Header can contain encoded words
=? charset ? encoding ? encoded-text ?=
– Charset can be us-ascii or iso-8859-1
– Encoding can be quoted-printable (Q) or base-64
(B)
• Using base-64, three consecutive bytes are encoded as
four 6-bit values
From: =?US-ASCII?Q?Keith_Moore?= <[email protected]>
To:=?ISO-8859-1?Q?Keld_j=F8rn_Sim?= <[email protected]>
Subject:=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?==?ISO8859-2?B?dSB1bmR1cnN0YW5kIHRoZSBleGFtcGxlLg==?=
Netprog: Email Protocols
18
Multipurpose Internet Mail
Extensions
• Problems:
–
–
–
–
Messages in languages with accents ( French and German)
non-Latin alphabets (Russian and Hebrew)
languages without alphabets (Chinese and Jamanese)
not containing text at all (audio or images)
• Need to add structure and define encoding rules for
non-ASCII messages.
Netprog: Email Protocols
19
Multipurpose Internet Mail
Extensions
• Allow structures in body
• Five new header fields
Mime-Version:
Content-Type: (Type and format of the content)
Content-Transfer-Encoding: (How body is wrapped for transmission)
Content-ID:
Content-Description: (Human-readable string telling what is in the
message)
• Seven content types: text, multipart, message, application, image,
audio, video
Mime-Version:1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
TEXT/ENRICHED, IMAGE/JPEG, VIDEO/MPEG, MESSAGE/EXTERNALBODY, MULTIPART/ALTERNATIVE… (more examples in the book)
• Five encoding formats: 7bit, quoted-printable, base64, 8bit, binary
Netprog: Email Protocols
20
Multipart/mixed
From: Nathaniel Borenstein <[email protected]>
To: Ned Freed <[email protected]>
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple boundary"
This is the preamble. It is to be ignored, though it is a handy place for mail composers to
include an explanatory note to non-MIME compliant readers.
--simple boundary
This is implicitly typed plain ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; charset=us-ascii
This is explicitly typed plain ASCII text.
It DOES end with a linebreak.
--simple boundary-This is the epilogue. It is also to be ignored.
Netprog: Email Protocols
21
Multipart/alternative
From: Nathaniel Borenstein <[email protected]>
To: Ned Freed <[email protected]>
Subject: Formatted text mail
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=boundary42
--boundary42
Content-Type: text/plain; charset=us-ascii
...plain text version of message goes here....
--boundary42
Content-Type: text/richtext
.... <bold>richtext</bold> version of same message goes here ...
--boundary42
Content-Type: text/x-whatever
.... fanciest formatted version of same message goes here
...
--boundary42 --
Netprog: Email Protocols
22
POP – Post Office Protocol
• Used to transfer mail from a mail server
to a UA.
Mail
Server
POP
UA
File
System
Netprog: Email Protocols
23
POP (version 3)
• Similar to SMTP command/reply
lockstep protocol.
• Used to retrieve mail for a single user
– requires authentication
• Commands and replies are ASCII lines.
– Replies start with “+OK” or “-ERR”.
– Replies may contain multiple lines.
Netprog: Email Protocols
24
POP-3 Commands
• USER - specify username
• PASS - specify password
• STAT - get mailbox status
– number of messages in the mailbox.
• LIST - get a list of messages and
sizes.
– One per line, termination line contains
‘.’ only.
• RETR - retrieve a message
Netprog: Email Protocols
25
More POP-3 Commands
• DELE - mark a message for deletion
from the mailbox.
• NOOP - send back positive reply
• RSET - reset. All deletion marks are
unmarked.
• QUIT - remove marked messages and
close the (TCP) connection.
Netprog: Email Protocols
26
Optional Commands
• TOP - send header lines from messages.
• APOP - alternative authentication
– APOP name digest
– a string identifying a mailbox and a MD5 digest string
– `digest‘: is calculated by applying the MD5 algorithm to a
string consisting of the timestamp (sent from POP server)
followed by a shared secret.
– Requires shared secret!
– No clear text password on the network.
– Does not authenticate the server!!!!
Netprog: Email Protocols
27
A Pop3 Exchange
> telnet hub0.engr.sc.edu 110
Trying 129.252.21.22...
Connected to hub0.engr.sc.edu.
Escape character is '^]'.
+OK Microsoft Exchange Server 2007 POP3 service
ready
…
quit
+OK Microsoft Exchange Server 2007 POP3 server
signing off.
Netprog: Email Protocols
28
A Pop3 Exchange
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
S:
S:
S:
S:
C:
S:
S:
S:
C:
S:
C:
S:
S:
S:
C:
S:
C:
S:
<wait for connection on TCP port 110>
<open connection>
+OK POP3 server ready <[email protected]>
USER mrose
+OK User accepted
PASS mrosepass
+OK Pass accepted
STAT
+OK 2 320
LIST
+OK 2 messages (320 octets)
1 120
2 200
.
RETR 1
+OK 120 octets
<the POP3 server sends message 1>
.
DELE 1
+OK message 1 deleted
RETR 2
+OK 200 octets
<the POP3 server sends message 2>
.
DELE 2
+OK message 2 deleted
QUIT
+OK dewey POP3 server signing off (maildrop empty)
Netprog: Email Protocols
29
APOP
S:
C:
S:
C:
S:
S:
S:
C:
S:
S:
S:
C:
S:
C:
+OK POP3 server ready [email protected]
APOP mrose c4c9334bac560ecc979e58001b3e22fb
+OK maildrop has 1 message (369 octets)
LIST
+OK 1 messages (320 octets)
1 320
.
RETR 1
+OK 320 octets
<the POP3 server sends message 1>
.
DELE 1
+OK message 1 deleted
QUIT
Netprog: Email Protocols
30
Descargar

IPv6 - University of South Carolina