230 likes | 380 Views
E-mail Internet Protocols. Simple Mail Transfer Protocol, SMTP RFC821 (August 1982) Post Office Protocol, POP3 RFC 1939 (May 1996) Internet Message Access Protocol, IMAP4 First RFC concerning IMAP - 1986 year RFC 1730 (IMAP4, December 1994) RFC 3501 (new edition of IMAP4v1, March 2003).
E N D
E-mail Internet Protocols • Simple Mail Transfer Protocol, SMTP • RFC821 (August 1982) • Post Office Protocol, POP3 • RFC 1939 (May 1996) • Internet Message Access Protocol, IMAP4 • First RFC concerning IMAP - 1986 year • RFC 1730 (IMAP4, December 1994) • RFC 3501 (new edition of IMAP4v1, March 2003) Rev. 1.04 / 11.01.2008 Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
E-mail transport scheme POP3 Mail Client, MTA (The Bat, Outlook) Mail Client, (The Bat, Outlook) telnet POP3 server User's mailboxes IMAP4 SMTP IMAP server SMTP server 1, MTA SMTP SMTP server 2, MTA SMTP SMTP destination server, MTA MDA MTA - Mail Transfer Agent MDA - Mail Delivery Agent Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
E-mail protocols and OSI RM SMTP, POP3, IMAP4 Layer 7 Layer 6 Layer 5 Layer 4 Layer 3 Layer 2 Layer 1 APPLICATION TCP IP Physical PRESENTATION SESSION TRANSPORT NETWORK DATA LINK PHYSICAL TCP/IP OSI/RM Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
SMTP features • Purpose: to transfer messages across a network. • In a single session multiple mail and information messages can be transmitted in either direction across the link. • By default an SMTP client application will contact the remote server using TCP/IP application port number 25 as the destination port, and will select at random a port from the dynamic or private range for the source port number. • SMTP provides a mechanism that allows mail to be sent directly from sender to recipient, or through intermediate hosts if there is no direct path from one to the other (DNS: MX record). Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
SMTP commands Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
SMTP replies Standard reply codes: 221(domain) Service closing transmission channel 220 (domain) Service ready 250 Requested mail action okay, completed 251User not local; will forward to (forward-path) 354Start mail input; end with (CRLF).(CRLF) 421(domain) Service not available, 500Syntax error, command unrecognized 501Syntax error in parameters or arguments 551User not local; please try “forward-path” 552Requested mail action aborted: exceeded storage allocation 554Transaction failed Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
SMTP session example S: Listen for connection on TCP port 25 C: Connect to TCP port 25 on SMTP server S: 220 mail.server.ru SMTP ready C: HELO my.domain.name S: 250 mail.server.ru C: MAIL FROM:<alex@alpha.ru> S: 250 OK C: RCPT TO:<boris@beta.ru> S: 250 OK C: RCPT TO:<paul@beta.ru> S: 550 No such user here C: RCPT TO:<paula@beta.ru> S: 250 OK C: DATA S: 354 Start mail input; end with <CRLF>.<CRLF> C: Blah blah blah... C: ...etc, etc, etc. C: <CRLF>.<CRLF> S: 250 OK C: QUIT S: 221 mail.server.arpa Service closing transmission channel Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
Mail message structure Received: from mx10.mail.ru (mx10.mail.ru [194.67.57.20]) (5) by dfe3300.karelia.ru (8.9.0/8.9.0) with ESMTP id JAA02601 for <somebody@dfe3300.karelia.ru>; Thu, 18 Apr 2002 09:19:13 +0400 Received: from f5.int ([10.0.0.57] helo=f5.mail.ru) (4) by mx10.mail.ru with esmtp (Exim MX.A) id 16y46p-0002ox-00 for somebody@dfe3300.karelia.ru; Thu, 18 Apr 2002 09:05:27 +0400 Received: from mail by f5.mail.ru with local (Exim FE.5) (3) id 16y46o-000CfY-00 for somebody@dfe3300.karelia.ru; Thu, 18 Apr 2002 09:05:26 +0400 Received: from [213.59.200.7] by win.mail.ru with HTTP; (2) Thu, 18 Apr 2002 09:05:26 +0400 From: "Testing" <testing@mail.ru> To: somebody@dfe3300.karelia.ru Subject: For testing purposes only Mime-Version: 1.0 X-Mailer: mPOP Web-Mail 2.19 X-Originating-IP: [213.59.200.7] (1) Date: Thu, 18 Apr 2002 09:05:26 +0400 Reply-To: "Testing" <testing@mail.ru> Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit Message-Id: <E16y46o-000CfY-00@f5.mail.ru> X-UIDL: 74fb663e2be8352b3a0b88ca08030c1e Тестовое сообщение. BLUE text was created by originating mail agent (mail client). 4 headers (Received:) were added on each SMTP interaction (hop) (2-5). Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
CC: and BCC: headers CC - carbon copy BCC - "blind" carbon copy When sending mail message through BCC mechanism to multiple recipients, they do not know about the fact of spam. MTA cuts out < BCC: …> string from message body and then sends multiple distinct letters using RCPT command. Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
POP3 features • Purpose: to retrieve mail from server. • Dedicated client and server hosts. • POP3 service is mapped to TCP port 110. • When the TCP connection is established, the POP3 server sends a greeting. The client and POP3 server then exchange commands and responses (respectively) until the connection is closed or aborted. • Multistring reply must end by <CRLF>.<CRLF> Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
POP3 commands Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
POP3 session example S: <wait for connection on TCP port 110> C: <open connection> S: +OK POP3 server ready <1896.697270952@dbc.ca.us> C: APOP mrose c4c9334bac560ecc979e58001b3e22fb S: +OK mrose's maildrop has 2 messages (320 octets) C: LIST S: +OK 2 messages (320 octets) S: 1 120 S: 2 200 S: . C: RETR 1 S: +OK 120 octets S: <the POP3 server sends message 1> S: . C: DELE 1 S: +OK message 1 deleted C: RETR 2 S: +OK 200 octets S: <the POP3 server sends message 2> S: . C: DELE 2 S: +OK message 2 deleted C: QUIT S: +OK dewey POP3 server signing off (maildrop empty) C: <close connection> S: <wait for next connection> Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP vs POP3 • POP3: all messages are downloaded to the client and then deleted from server. • IMAP: accesses remote mail-boxes as if they were present on the local machine. • The IMAP4 client can request any part of the message, such as the envelope or the headers and download the whole message only when needed. • Server based searching is also supported. • Messages are not deleted immediately, rather they are marked for deletion and only removed once the client logs off or sends the expunge command. • POP3: useful for people working with one computer. • IMAP: Because the messages are stored on the server, it doesn't really matter who or where the client is (synchronization). Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 description • Purpose: to allows a client to access and manipulate electronic mail messages on a server. • Messages in IMAP4rev1 are accessed by the use of numbers. These numbers are either message sequence numbers or unique identifiers. • The IMAP4rev1 protocol assumes a reliable data stream such as thatprovided by TCP. When TCP is used(!), an IMAP4rev1 server listens onport 143. • The client command begins an operation. Each client command isprefixed with an identifier (typically a short alphanumeric string,e.g., A0001, A0002, etc.) called a "tag". A different tag isgenerated by the client for each command. • Client need not wait for reply on certain command, it can issue next command to execute Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 session states Transport connection and server greeting greeting/OK LOGIN successful greeting/ PREAUTH greeting/bye Non-authenticated Authenticated (operations involving mailboxes) SELECT / EXAMINE Selected (operations involving messages) Logout, break or close connection Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 description cont'd Message attributes: • Unique Identifier (UID) (32 bit, greater than previous) • Message Sequence Number (position of message in mailbox, can be reassigned during the session) • Internal date • Size • Envelope structure (parsed headers part) • Body structure (parsed structure of MIME content) • Flags: • \Seen Message has been read • \Answered Message has been answered • \Flagged Message is "flagged" for urgent/special attention • \Deleted Message is "deleted" for removal by later EXPUNGE • \Draft Message is marked as a draft. • \Recent Message is "recently" arrived in this mailbox (only for 1st read-write session). Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 client commands CAPABILITY: requests a listing of capabilities that the server supports (valid in any state). Example: C: a001 CAPABILITY S: * CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED S: a001 OK CAPABILITY completed C: a002 STARTTLS S: a002 OK STARTLS completed <TLS negotiation, further commands are under [TLS] layer> C: a003 CAPABILITY S: * CAPABILITY IMAP4rev1 AUTH=GSSAPI AUTH=PLAIN S: a003 OK CAPABILITY completed C: a004 LOGIN joe password S: a004 OK LOGIN completed Server made client to establish TLS connection. Note: strings beginning with * correspond to the reply with the following tag number. Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 client commands SELECT: selects a mailbox so that messages in the mailbox can be accessed (valid in Authenticated State). Example: C: A142 SELECT INBOX S: * 172 EXISTS S: * 1 RECENT S: * OK [UNSEEN 12] Message 12 is first unseen S: * OK [UIDVALIDITY 3857529045] UIDs valid (session ID) S: * OK [UIDNEXT 4392] Predicted next UID S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited S: A142 OK [READ-WRITE] SELECT completed EXAMINE: the same as SELECT but the selected mailbox is identified as read-only. Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 client commands CREATE: creates a mailbox with the given name (valid in Authenticated State). Example: C: A003 CREATE mailbox2/ S: A003 OK CREATE completed DELETE: deletes a mailbox with the given name (valid in Authenticated State). Example: C: A104 DELETE mailbox2/ S: A104 OK DELETE completed Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 client commands Selected State CLOSE: removes all messages that have the \Deleted flag set from the currently selected mailbox, and returns to the authenticated state from the selected state. EXPUNGE: removes all messages that have the \Deleted flag set from the currently selected mailbox. SEARCH: searches the mailbox for messages that match the given searching criteria. Example: C: A282 SEARCH FLAGGED SINCE 1-Feb-1994 NOT FROM "Smith" S: * SEARCH 2 84 882 Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 client commands Selected State FETCH: retrieves data associated with a message in the mailbox. STORE: alters data associated with a message in the mailbox. COPY: copies selected messages to the end of the specified destination mailbox. Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 session example S: * OK IMAP4rev1 Service Ready C: a001 login mrc secret S: a001 OK LOGIN completed C: a002 select inbox S: * 18 EXISTS S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) S: * 2 RECENT S: * OK [UNSEEN 17] Message 17 is the first unseen message S: * OK [UIDVALIDITY 3857529045] UIDs valid S: a002 OK [READ-WRITE] SELECT completed C: a003 fetch 12 full S: * 12 FETCH (FLAGS (\Seen) INTERNALDATE "17-Jul-1996 02:44:25 -0700" RFC822.SIZE 4286 ENVELOPE ("Wed, 17 Jul 1996 02:23:25 -0700 (PDT)" "IMAP4rev1 WG mtg summary and minutes" (("Terry Gray" NIL "gray" "cac.washington.edu")) (("Terry Gray" NIL "gray" "cac.washington.edu")) (("Terry Gray" NIL "gray" "cac.washington.edu")) ((NIL NIL "imap" "cac.washington.edu")) ((NIL NIL "minutes" "CNRI.Reston.VA.US") ("John Klensin" NIL "KLENSIN" "MIT.EDU")) NIL NIL "<B27397-0100000@cac.washington.edu>") BODY ("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 3028 92)) S: a003 OK FETCH completed Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES
IMAP4v1 session example C: a004 fetch 12 body[header] S: * 12 FETCH (BODY[HEADER] {342} S: Date: Wed, 17 Jul 1996 02:23:25 -0700 (PDT) S: From: Terry Gray <gray@cac.washington.edu> S: Subject: IMAP4rev1 WG mtg summary and minutes S: To: imap@cac.washington.edu S: cc: minutes@CNRI.Reston.VA.US, John Klensin <KLENSIN@MIT.EDU> S: Message-Id: <B27397-0100000@cac.washington.edu> S: MIME-Version: 1.0 S: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII S: S: ) S: a004 OK FETCH completed C: a005 store 12 +flags \deleted S: * 12 FETCH (FLAGS (\Seen \Deleted)) S: a005 OK +FLAGS completed C: a006 logout S: * BYE IMAP4rev1 server terminating connection S: a006 OK LOGOUT completed As a result, message number 12 was deleted from mailbox. Petrozavodsk State University, Alex Moschevikin, 2003 NET TECHNOLOGIES