Email SMTP Simple Mail Transfer Protocol RFC 821

  • Slides: 30
Download presentation
Email • SMTP - Simple Mail Transfer Protocol – RFC 821 • POP -

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

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

SMTP Used to exchange mail messages between mail servers (Message Transfer Agents). MTA SMTP MTA File System SMTP UA UA Netprog: Email Protocols 3

SMTP Protocol • • SMTP sender is the client SMTP receiver is the server.

SMTP Protocol • • SMTP sender is the client SMTP receiver is the server. The communication use NVT ASCII. Alternating dialogue: – client sends command 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

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 rn. 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

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> this message is a

Leading Period DATA 354 Start mail input; end with <CRLF> this message is a test of SMTP. . foo. . . 250 2. 6. 0 <c 2 b 1 c 1 a 0 -3951 -4 fd 6 -b 6 fb-675 c 0 ee 4 a 0 dd> Queued mail for delivery Resulting Message: this message is a test of SMTP. . foo. Netprog: Email Protocols 7

Typical Exchange wyxu@canopus % telnet hub 0. engr. sc. edu 25 Trying 129. 252.

Typical Exchange wyxu@canopus % telnet hub 0. engr. sc. edu 25 Trying 129. 252. 21. 22. . . Connected to hub 0. engr. sc. edu. Escape character is '^]'. 220 HUB 0. engr. sc. edu Microsoft ESMTP MAIL Service ready at Sat, 17 Nov 2007 20: 18: 49 -0500 HELO 250 HUB 0. engr. sc. edu Hello [129. 252. 130. 106] MAIL from: <wyxu@engr. sc. edu> 250 2. 1. 0 Sender OK RCPT to: <wyxu@cse. sc. edu> 250 2. 1. 5 Recipient OK DATA 354 Start mail input; end with <CRLF> Subject: test from: sender@bla. com to: receiver@bla. com this is a test mail. 250 2. 6. 0 <c 2 b 1 c 1 a 0 -3951 -4 fd 6 -b 6 fb-675 c 0 ee 4 a 0 dd> Queued mail for delivery Netprog: Email Protocols 8

Other SMTP Commands VRFY - confirm that a name is a valid recipient. S:

Other SMTP Commands VRFY - confirm that a name is a valid recipient. S: VRFY Smith R: 250 Fred Smith <Smith@USC-ISIF. ARPA> EXPN - expand an alias (group email address). S: R: R: R: EXPN Example-People 250 -Jon Postel <Postel@USC-ISIF. ARPA> 250 -Fred Fonebone <Fonebone@USC-ISIQ. ARPA> 250 -Sam Q. Smith <SQSmith@USC-ISIQ. ARPA> 250 -Quincy Smith <@USC-ISIF. ARPA: Q-Smith@ISI-VAXA. ARPA> 250 -<joe@foo-unix. ARPA> 250 <xyz@bar-unix. ARPA> TURN - switch roles (sender <=> receiver). Netprog: Email Protocols 9

more Commands SOML - Send Or Mail if recipient is logged in, display message

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

Envelopes, Headers, and Body • Envelopes are used by MTAs for delivery – Specified by MAIL and RCPT commands • MAIL from: <wyxu@engr. sc. edu> • RCPT to: <wyxu@cse. sc. edu> • 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

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

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 foo@cs. vu. nl • MTA asks the DNS for

Transmission of a mail to foo@cs. vu. nl • 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 130. 37. 16. 112 130. 37. 16. 6 Netprog: Email Protocols 14

Transmission of a mail to foo@cs. vu. nl • MTA asks the DNS for

Transmission of a mail to foo@cs. vu. nl • 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 130. 37. 16. 112 130. 37. 16. 6 Netprog: Email Protocols 15

Improvements on SMTP • Envelope changes: Extended SMTP • Header changes: Non-ASCII characters •

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

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

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? = <moore@cs. utk. edu> To: =? ISO-8859 -1? Q? Keld_j=F 8 rn_Sim? = <test@gmail. com> Subject: =? ISO-8859 -1? B? SWYge. W 91 IGNhbi. By. ZWFk. IHRoa. XMge. W 8=? ==? ISO 8859 -2? B? d. SB 1 bm. R 1 cn. N 0 YW 5 k. IHRo. ZSBle. GFtc. Gxl. Lg==? = Netprog: Email Protocols 18

Multipurpose Internet Mail Extensions • Problems: – – Messages in languages with accents (

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

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: 7 bit, quoted-printable, base 64, 8 bit, binary Netprog: Email Protocols 20

Multipart/mixed From: Nathaniel Borenstein <nsb@bellcore. com> To: Ned Freed <ned@innosoft. com> Subject: Sample message

Multipart/mixed From: Nathaniel Borenstein <nsb@bellcore. com> To: Ned Freed <ned@innosoft. com> 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 <nsb@bellcore. com> To: Ned Freed <ned@innosoft. com> Subject: Formatted text

Multipart/alternative From: Nathaniel Borenstein <nsb@bellcore. com> To: Ned Freed <ned@innosoft. com> Subject: Formatted text mail MIME-Version: 1. 0 Content-Type: multipart/alternative; boundary=boundary 42 --boundary 42 Content-Type: text/plain; charset=us-ascii. . . plain text version of message goes here. . --boundary 42 Content-Type: text/richtext. . <bold>richtext</bold> version of same message goes here. . . --boundary 42 Content-Type: text/x-whatever. . fanciest formatted version of same message goes here. . . --boundary 42 -- Netprog: Email Protocols 22

POP – Post Office Protocol • Used to transfer mail from a mail server

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

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

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.

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

Optional Commands • TOP - send header lines from messages. • APOP - alternative authentication – APOP name digest – a string identifying a mailbox and a MD 5 digest string – `digest‘: is calculated by applying the MD 5 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 Pop 3 Exchange > telnet hub 0. engr. sc. edu 110 Trying 129.

A Pop 3 Exchange > telnet hub 0. engr. sc. edu 110 Trying 129. 252. 21. 22. . . Connected to hub 0. engr. sc. edu. Escape character is '^]'. +OK Microsoft Exchange Server 2007 POP 3 service ready … quit +OK Microsoft Exchange Server 2007 POP 3 server signing off. Netprog: Email Protocols 28

A Pop 3 Exchange S: C: S: C: S: S: S: C: S: <wait

A Pop 3 Exchange S: C: S: C: S: S: S: C: S: <wait for connection on TCP port 110> <open connection> +OK POP 3 server ready <1896. 697170952@dbc. mtview. ca. us> 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 POP 3 server sends message 1>. DELE 1 +OK message 1 deleted RETR 2 +OK 200 octets <the POP 3 server sends message 2>. DELE 2 +OK message 2 deleted QUIT +OK dewey POP 3 server signing off ( maildrop empty) Netprog: Email Protocols 29

APOP S: C: S: S: S: C: +OK POP 3 server ready 1896. 697170952@dbc.

APOP S: C: S: S: S: C: +OK POP 3 server ready 1896. 697170952@dbc. mtview. ca. us APOP mrose c 4 c 9334 bac 560 ecc 979 e 58001 b 3 e 22 fb +OK maildrop has 1 message (369 octets) LIST +OK 1 messages (320 octets) 1 320. RETR 1 +OK 320 octets <the POP 3 server sends message 1>. DELE 1 +OK message 1 deleted QUIT Netprog: Email Protocols 30