Transcript Document

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
Mail Client,
MTA (The Bat,
Outlook)
Mail Client,
(The Bat,
Outlook)
POP3
POP3 server
SMTP
IMAP4
SMTP SMTP SMTP SMTP
server 1,
server 2,
MTA
MTA
telnet
User's
mailboxes
IMAP server
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
APPLICATION
TCP
IP
Physical
PRESENTATION
SESSION
TRANSPORT
NETWORK
DATA LINK
PHYSICAL
TCP/IP
Petrozavodsk State University, Alex Moschevikin, 2003
Layer 7
Layer 6
Layer 5
Layer 4
Layer 3
Layer 2
Layer 1
OSI/RM
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
HELO domain
identify the client to the server ("hello, I'm...")
MAIL FROM:
reverse-path
initiate mail transaction; arg is sender's address
RCPT TO: forward- recipient's address (issue for each recipient once)
path
DATA
followed by the mail message (up to CRLF.CRLF)
HELP [command]
ask for general help or about a specific command
RSET
abort current mail transaction, reply OK
NOOP
no-op, server responds OK
QUIT
terminate session, server responds OK
TURN
change roles: server/client; server may refuse
...
...
Petrozavodsk State University, Alex Moschevikin, 2003
NET TECHNOLOGIES
SMTP replies
Standard reply codes:
221
220
250
251
354
421
500
501
551
552
554
(domain) Service closing transmission channel
(domain) Service ready
Requested mail action okay, completed
User not local; will forward to (forward-path)
Start mail input; end with (CRLF).(CRLF)
(domain) Service not available,
Syntax error, command unrecognized
Syntax error in parameters or arguments
User not local; please try “forward-path”
Requested mail action aborted: exceeded storage allocation
Transaction failed
Petrozavodsk State University, Alex Moschevikin, 2003
NET TECHNOLOGIES
SMTP session example
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
S:
C:
S:
Listen for connection on TCP port 25
Connect to TCP port 25 on SMTP server
220 mail.server.ru SMTP ready
HELO my.domain.name
250 mail.server.ru
MAIL FROM:<[email protected]>
250 OK
RCPT TO:<[email protected]>
250 OK
RCPT TO:<[email protected]>
550 No such user here
RCPT TO:<[email protected]>
250 OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Blah blah blah...
...etc, etc, etc.
<CRLF>.<CRLF>
250 OK
QUIT
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 <[email protected]>; 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 [email protected]; 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 [email protected]; 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" <[email protected]>
To: [email protected]
BLUE text was
Subject: For testing purposes only
created by
Mime-Version: 1.0
originating mail
X-Mailer: mPOP Web-Mail 2.19
agent (mail
X-Originating-IP: [213.59.200.7] (1)
client).
Date: Thu, 18 Apr 2002 09:05:26 +0400
Reply-To: "Testing" <[email protected]>
4 headers
Content-Type: text/plain; charset=koi8-r
(Received:) were
Content-Transfer-Encoding: 8bit
added on each
Message-Id: <[email protected]>
SMTP interaction
X-UIDL: 74fb663e2be8352b3a0b88ca08030c1e
(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
USER name
string identifying a mailbox (required)
PASS passwd a server/mailbox-specific password (required)
APOP name
MD5digest
a string identifying a mailbox and a MD5 digest string
(both required)
STAT
inquire the content of mailbox (reply: +OK 2 320 -- 2
messages of overall volume of 320 octets)
LIST [msg]
list [all] messages
RETR msg
retrieve the certain message
DELE msg
delete the certain message
RSET
reset all previous prepared actions, reply +OK
NOOP
no-op, server responds +OK
QUIT
terminate session
...
...
Petrozavodsk State University, Alex Moschevikin, 2003
NET TECHNOLOGIES
POP3 session example
S:
C:
S:
C:
S:
C:
S:
S:
S:
S:
C:
S:
S:
S:
C:
S:
C:
S:
S:
S:
C:
S:
C:
S:
C:
S:
<wait for connection on TCP port 110>
<open connection>
+OK POP3 server ready <[email protected]>
APOP mrose c4c9334bac560ecc979e58001b3e22fb
+OK mrose's maildrop has 2 messages (320 octets)
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)
<close connection>
<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
that provided by TCP. When TCP is used (!), an IMAP4rev1 server
listens on port 143.
• The client command begins an operation. Each client command
is prefixed with an identifier (typically a short alphanumeric string,
e.g., A0001, A0002, etc.) called a "tag". A different tag is generated
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
greeting/bye
Non-authenticated
LOGIN
successful
greeting/
PREAUTH
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:
1. \Seen
Message has been read
2. \Answered Message has been answered
3. \Flagged Message is "flagged" for urgent/special attention
4. \Deleted
Message is "deleted" for removal by later EXPUNGE
5. \Draft
Message is marked as a draft.
6. \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:
C:
S:
C:
S:
S:
S:
S:
S:
S:
C:
S:
S:
* OK IMAP4rev1 Service Ready
a001 login mrc secret
a001 OK LOGIN completed
a002 select inbox
* 18 EXISTS
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* 2 RECENT
* OK [UNSEEN 17] Message 17 is the first unseen message
* OK [UIDVALIDITY 3857529045] UIDs valid
a002 OK [READ-WRITE] SELECT completed
a003 fetch 12 full
* 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
"<[email protected]>")
BODY ("TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 3028
92))
a003 OK FETCH completed
Petrozavodsk State University, Alex Moschevikin, 2003
NET TECHNOLOGIES
IMAP4v1 session example
C:
S:
S:
S:
S:
S:
S:
S:
S:
S:
S:
S:
S:
C:
S:
S:
C:
S:
S:
a004 fetch 12 body[header]
* 12 FETCH (BODY[HEADER] {342}
Date: Wed, 17 Jul 1996 02:23:25 -0700 (PDT)
From: Terry Gray <[email protected]>
Subject: IMAP4rev1 WG mtg summary and minutes
To: [email protected]
cc: [email protected], John Klensin <[email protected]>
Message-Id: <[email protected]>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
)
a004 OK FETCH completed
a005 store 12 +flags \deleted
* 12 FETCH (FLAGS (\Seen \Deleted))
a005 OK +FLAGS completed
a006 logout
* BYE IMAP4rev1 server terminating connection
a006 OK LOGOUT completed
As a result, message number 12 was deleted from mailbox.
Petrozavodsk State University, Alex Moschevikin, 2003
NET TECHNOLOGIES