Email by jizhen1947


									Electronic Mail

                  Application Layer   1
Electronic Mail                                              outgoing
                                                        message queue
                                                          user mailbox
Three major components:                    user
 user agents                             agent
 mail servers                    mail
 simple mail transfer                                        agent
  protocol: SMTP                           SMTP       mail
                                                     server      user
User Agent
                                SMTP                            agent
 a.k.a. “mail reader”
 composing, editing, reading              SMTP
                                  mail                         user
  mail messages                                               agent
 e.g., Eudora, Outlook, elm,
  Netscape Messenger                        user
 outgoing, incoming messages              agent
  stored on server                agent

                                                   Application Layer     2
Electronic Mail: mail servers
Mail Servers                              agent
 mailbox contains incoming       mail
  messages for user              server
 message queue of outgoing
  (to be sent) mail messages                             mail
                                                        server          user
 SMTP protocol between mail
  servers to send email         SMTP                                   agent

  messages                                 SMTP
    client: sending mail         mail                            user
      server                     server
    “server”: receiving mail
      server                               agent

                                                   Application Layer      3
The Entire E-mail System

                       Application Layer   4
Electronic Mail: SMTP [RFC 2821]
 uses TCP to reliably transfer email message from client to server, port
       SMTP uses persistent connections
 direct transfer: sending server to receiving server
 three phases of transfer
    handshaking (greeting)
    transfer of messages
    closure
 command/response interaction
    commands: ASCII text
    response: status code and phrase
 SMTP uses info written on envelope of mail
       Message header
 Does not look at contents
    Message body
 messages must be in 7-bit ASCII
 Other functions:
    E-mail address lookup
    E-mail address verification

                                                        Application Layer   5
Scenario: Alice sends message to Bob
1) Alice uses UA to compose          4) SMTP client sends Alice’s
   message and “to”                     message over the TCP                   connection
2) Alice’s UA sends message          5) Bob’s mail server places the
   to her mail server; message          message in Bob’s mailbox
   placed in message queue           6) Bob invokes his user agent
3) Client side of SMTP opens            to read message
   TCP connection with Bob’s
   mail server

       1                                  mail
                                         server          user
       user       server
              2                                         agent
      agent         3                              6
                                 4         5

                                                       Application Layer   6
Sample SMTP interaction
S:   220
S:   250 Hello, pleased to meet you
C:   MAIL FROM: <>
S:   250 Sender ok
C:   RCPT TO: <>
S:   250 ... Recipient ok
S:   354 Enter mail, end with "." on a line by itself
C:   Do you like ketchup?
C:   How about pickles?
C:   .
S:   250 Message accepted for delivery
S:   221 closing connection

                                        Application Layer   7
Try SMTP interaction for yourself:

 telnet servername 25
 see 220 reply from server
above lets you send email without using email client

                                            Application Layer   8
[codd:~] [4:18pm] -> telnet 25
Connected to
Escape character is '^]'.
220 ESMTP Sendmail 8.9.3/8.9.3;
Mon, 12 Nov 2001 16:18:18 -0500 (EST)
250 Hello
[], pleased to meet you
250 Sender ok
250 Recipient ok
354 Enter mail, end with "." on a line by itself
This is a test mail message to myself!!!
250 Message accepted for delivery
221 closing connection
Connection closed by foreign host.
                                             Application Layer   9
Mail Message Contents
 Each queued message has:
   Message    text
    • RFC 822 header with message envelope and
      list of recipients
    • Message body, composed by user
  A    list of mail destinations
    •   Derived by user agent from header
    •   May be listed in header
    •   May require expansion of mailing lists
    •   May need replacement of mnemonic names
        with mailbox names
                                       Application Layer   10
Possible Errors
 Host unreachable
 Host out of operation
 TCP connection fail during transfer
 Sender can re-queue mail
     Give up after a period
 Faulty destination address
    User error
    Target user changed address
    Redirect if possible
    Inform user if not
                                    Application Layer   11
SMTP System Overview
 Commands and responses between sender
  and receiver
 Initiative with sender
      Establishes TCP connection
 Sender sends commands to receiver
 e.g.   HELO<SP><domain><CRLF>
 Each command generates exactly one reply
     250 requested mail action ok;
 e.g.

                                     Application Layer   12
SMTP Replies
 Leading digit indicates category
   Positive completion reply (2xx)
   Positive intermediate reply (3xx)
   Transient negative completion reply (4xx)
   Permanent negative completion reply (5xx)

                                        Application Layer   13
Operation Phases
 Connection setup
 Exchange of command-response pairs
 Connection termination

                                 Application Layer   14
Connection Setup
 Sender opens TCP connection with receiver
 Once connected, receiver identifies itself
     220 <domain> service ready
 Sender identifies itself
     HELO
 Receiver accepts sender’s identification
     250 OK
 If mail service not available, step 2 above
     421 service not available
                                      Application Layer   15
Mail Transfer
 Sender may send one or more messages to
 MAIL command identifies originator
    Gives reverse path to used for error reporting
    Receiver returns 250 OK or appropriate
     fail/error message
 One or more RCPT commands identifies
  recipients for the message
      Separate reply for each recipient
 DATA command transfers message text
   End of message indicated by line containing just
    period (.)
                                           Application Layer   16
Closing Connection
 Two steps
 Sender sends QUIT and waits for reply
 Then initiate TCP close operation
 Receiver initiates TCP close after sending
  reply to QUIT

                                      Application Layer   17
Electronic Mailboxes and
 E-mail users have an electronic mailbox
  into which mail is deposited
 Usually associated with computer account;
  one user may have different electronic
 User accesses mail with a mail reader
 Electronic mailbox is identified by an e-
  mail address
                                    Application Layer   18
Internet Mail Addressing
 User portion or mailbox portion is site specific
    Dang
    XuanHien_T_Dang
    1234.5678

 Host portion or computer portion is domain name
 Source mail client
    Resolves destination name using DNS (MX, if available)
    Contacts mail delivery server at destination
    Copies mail to server

 Destination mail server
    Interprets user name according to local mailbox addresses
    Places mail in appropriate mailbox

                                                  Application Layer   19
E-mail message format
 Simple two-part format
   Header includes delivery information
   Body carries text of message

 Header and body separated by blank line

                                           Application Layer   20
Mail message format

SMTP: protocol for
  exchanging email msgs       header
RFC 822: standard for text
  message format:
 header lines, e.g.,
      From:
      Subject:
   different from SMTP
 body
      the “message”, ASCII
       characters only

                                     Application Layer     21
E-mail Headers
 Lines of text in format         keyword: information
   keyword identifies information; information can
  appear in any order
 Essential information:
       To: list of recipients
       From: sender
       Cc: list of copy recipients
 Useful information
    Reply-to: different address than From:
    Received-by: for debugging

 Frivolous information:
    Favorite drink: lemonade
    Phase-of-the-moon: gibbous

                                                 Application Layer   22
Data in E-mail
 Original Internet mail carried only 7-bit ASCII
 Couldn’t contain arbitrary binary values; e.g.,
  executable program
 Techniques for encoding binary data allowed
  transport of binary data
 Uuencode: three 8-bit binary values as four ASCII
  characters (6 bits each)
      Also carries file name and protection information
      Incurs 33% overhead
      Requires manual intervention

                                                    Application Layer   23
Multipurpose Internet Mail
Extension (MIME)
 Extension to RFC822
 SMTP cannot transmit executables
      Uuencode and other schemes are available
        • Not standardized
 Can not transmit text including international characters (e.g.
  â, å, ä, è, é, ê, ë)
      Need 8 bit ASCII
 Servers may reject mail over certain size
 Translation between ASCII and EBCDIC not standard
 SMTP gateways to X.400 can not handle none text data in
  X.400 messages
 Some SMTP implementations do not adhere to standard
      CRLF, truncate or wrap long lines, removal of white space, etc.

                                                          Application Layer   24
   Multipart Internet Mail Extensions - Extends and
  automates encoding mechanisms
 Allows inclusion of separate components – programs,
  pictures, audio clips – in a single mail message
 Sending program identifies the components so
  receiving program can automatically extract and
  inform mail recipient
       Header includes
        MIME-Version: 1.0
        Content-Type: Multipart/Mixed; Boundary=Mime_separator
       Separator line gives information about specific encoding
        Content-Type: text/plain

                                                   Application Layer   25
MIME (cont.)
 MIME is extensible – sender and receiver
  agree on encoding scheme
 MIME is compatible with existing mail
   Everything encoded as ASCII
   Headers and separators ignored by non-MIME
    mail systems
 MIME encapsulates binary data in ASCII
  mail envelope

                                      Application Layer   26

       Application Layer   27
Overview of MIME
 Five new message header fields
   MIME version
   Content type
   Content transfer encoding
   Content Id
   Content Description

 Number of content formats defines
 Transfer encoding defined

                                   Application Layer   28
Content Types
 Text body
 Multipart
   Mixed, Parallel, Alternative, Digest

 Message
   RFC 822, Partial, External-body

 Image
    jpeg, gif

 Video
    mpeg

 Audio
    Basic

 Application
    Postscript
    octet stream                          Application Layer   29
MIME Transfer Encodings
 Reliable delivery across wide largest range of
 Content transfer encoding field
      Six values
      Three (7bit, 8bit, binary) no encoding done
        • Provide info about nature of data
 Quoted-printable
   Data largely printable ASCII characters
   Non-printing characters represented by hex code

 Base64
    Maps arbitrary binary input onto printable output

 X-token
    Named nonstandard encoding                      Application Layer   30
   Message format: multimedia extensions
    MIME: multimedia mail extension, RFC 2045, 2056
    additional lines in msg header declare MIME content

      MIME version            To:
                              Subject: Picture of yummy crepe.
        method used           MIME-Version: 1.0
      to encode data          Content-Transfer-Encoding: base64
                              Content-Type: image/jpeg
     multimedia data
      type, subtype,          base64 encoded data .....
parameter declaration         .........................
                              ......base64 encoded data
       encoded data

                                                    Application Layer   31
Programs as mail recipients
 Can arrange for e-mailbox to be associated
  with a program rather than a user’s mail
 Incoming mail automatically processed as
  input to program
 Example – mailing list subscription
 Can be used to implement client-server
   Client request in incoming mail message
   Server response in returned mail reply
                                         Application Layer   32
Mailing Lists and Forwarders
 E-mail addresses can be attached to
  programs as well as electronic mailboxes
 Mail exploder or mail forwarder resends
  copies of message to e-mail addresses in
  mailing list
   UNIX mail program sendmail provides mail
   Mailing list processor, e.g. listserv, can also
    interpret subscription management commands

                                           Application Layer   33
Mail Gateways
 Mailing list processing may take significant
  resources in large organizations
 May be segregated to a dedicated server
  computer: mail gateway
   Provides single mail destination point for all
    incoming mail
   Can use MX records in DNS to cause all mail to
    be delivered to gateway

                                         Application Layer   34
Mail gateways and forwarding
 Users within an organization may want to
  read mail on local or departmental
 Can arrange to have mail forwarded from
  mail gateway
 Message now makes multiple hops for
 Hops may be recorded in header
 Forwarded mail may use proprietary (non-
  SMTP) mail system
                                    Application Layer   35
Mail Gateways and E-mail Addresses

 Organization may want to use uniform
  naming for external mail
 Internally, may be delivered to many
  different systems with different naming
 Mail gateways can translate e-mail

                                   Application Layer   36
Mailbox Access
 Where should mailbox be located?
 Users want to access mail from most
  commonly used computer
 Cannot always use desktop computer as
  mail server
   Not always running
   Requires multitasking OS
   Requires local disk storage

 Can TELNET to remote computer with mail
                                     Application Layer   37
Mail Access Protocols
 Typically users do NOT run a server on
  their local PC
 User agent accesses a mailbox from a
  shared mail server
 Mail access protocol transfers mail from
  server to local PC
 2 popular protocols:
   POP3 (Post Office Protocol v3)
   IMAP (Internet Mail Access Protocol)

 Can’t use SMTP because getting messages
  is a pull operation & SMTP is a push
  protocol.                          Application Layer   38
Mail Access Protocol
 Instead of TELNET, use protocol that
  accesses mail on remote computer directly
 TCP/IP suite includes Post Office Protocol
  (POP) for remote mailbox access
   Computer with mailboxes runs POP server
   User runs POP client on local computer
   POP client can access and retrieve messages
    from mailbox
   Requires authentication (password)
   Local computer uses SMTP for outgoing mail

                                        Application Layer   39
Email Protocols

                  Application Layer   40

                Application Layer   41
 Three phases
   Authorization
   Transaction
   Update

 During a POP3 session, the server
  maintains state information
 POP3 downloads mail messages to the local
  machine – not good for “nomadic user”

                                      Application Layer   42
POP3 protocol                  S:   +OK POP3 server ready
                               C:   user bob
authorization phase            S:   +OK
                               C:   pass hungry
 client commands:             S:   +OK user successfully logged    on
    user: declare username
                               C:   list
    pass: password            S:   1 498
 server responses             S:   2 912
                               S:   .
    +OK
                               C:   retr 1
    -ERR                      S:   <message 1 contents>
transaction phase, client:     S:   .
                               C:   dele 1
 list: list message numbers   C:   retr 2
 retr: retrieve message by    S:   <message 1 contents>
  number                       S:   .
                               C:   dele 2
 dele: delete
                               C:   quit
 quit                         S:   +OK POP3 server signing off
                                               Application Layer   43
Dialup Access and POP
 POP useful for dialup connection
   User’s computer not always connected
   Can download all mail at once and read off-line
   Can compose mail off-line and mail in one

                                          Application Layer   44
 Internet Mail Access Protocol
 Allows users to manipulate remote
 Must maintain info about user (e.g., folder
  hierarchy) even after the user quits
 IMAP server is always in 1 of 4 states:
   Nonauthenticated
   Authenticated
   Selected
   Logout

                                      Application Layer   45
More about POP3           IMAP
 Previous example uses    Keep all messages in
  “download and delete”     one place: the server
  mode.                    Allows user to
 Bob cannot re-read e-     organize messages in
  mail if he changes        folders
  client                   IMAP keeps user state
 “Download-and-keep”:      across sessions:
  copies of messages on        names of folders and
  different clients             mappings between
                                message IDs and folder
 POP3 is stateless
  across sessions

                                           Application Layer   46
Mail access protocols
                 SMTP         SMTP               access     user
         agent                                  protocol   agent

                  sender’s mail   receiver’s mail
                     server           server

 SMTP: delivery/storage to receiver’s server
 Mail access protocol: retrieval from server
      POP: Post Office Protocol [RFC 1939]
        • authorization (agent <-->server) and download
      IMAP: Internet Mail Access Protocol [RFC 1730]
        • more features (more complex)
        • manipulation of stored msgs on server
      HTTP: Hotmail , Yahoo! Mail, etc.

                                                       Application Layer   47
Web-based Emails
 Problem: Suppose Alice,        Solution:
  with a web-based email          Message is sent from
  account (such as Hotmail),      Alice’s host to her mail
  sends a message to Bob,         server over HTTP. Alice’s
  who accesses his mail from      mail server then sends the
  his mail server using POP3.     message to Bob’s mail
  Discuss how the message         server over SMTP. Bob
  gets from Alice’s host to       then transfers the
  Bob’s host. Be sure to list     message from his mail
  the series of application-      server to his host over
  layer protocols that are        POP3.
  used to move the message
  between the two hosts.

                                                 Application Layer   48
 Connections:                     All have ASCII
   – All use TCP                    command/response
   – SMTP uses persistent           interaction, status codes
   connections                     HTTP: each object
   – FTP persistent control         encapsulated in its own
                                    response msg
   channel, non-persistent data
                                   FTP: one data channel per
   channel per file.                file
   – HTTP uses both persistent     SMTP: multiple objects
   and non-persistent channels      sent in multipart msg
 Data Flow
   – FTP and HTTP: pull (user
   requests files)
   – SMTP: push (email sent to
   receiver without request,
   result can be spam!)

                                                   Application Layer   49
Summary for Email
 Electronic mail allows quick, asynchronous
  communication across entire Internet.
 Simple Mail Transfer Protocol (SMTP) is Internet
  standard for mail delivery
 Can attach e-mail addresses to programs for
      Mailing lists
      Other client-server applications
 Mail gateways
   Provide uniform user addressing outside organizations
   Translate from Internet mail (e.g. SMTP) to proprietary
 Post Office Protocol (POP) and Internet Mail
  Access Protocol (IMAP) allow remote access to
  electronic mailboxes.
                                               Application Layer   50

To top