© 2002 Huhns SMTP and POP3: Communicating with email Servers Defiana Arnaldy, M.Si 0818 0296 4763 deff_arnaldy@yahoo.com 1 • • • • • Service via Email Sending Email SMTP POP3 Conclusion © 2002 Huhns Overview 2 • Email is an Internet application that is available widely: it can be accessed from laptops, desktops, PDAs, mobile phones, and pagers • Imagine an application that can receive email from a user, perform the services requested by or on behalf of the user, and then send the results back to the user via email • The application uses the SMTP and POP3 protocols © 2002 Huhns Services via Email 3 • Every email must have a destination email address. An email address takes the following form: © 2002 Huhns Sending an email • The domain name in an email address generally does not include the “www” prefix, which is common for Web site addresses 4 © 2002 Huhns • Emails are not immediately delivered to the recipient; instead, they are initially sent to your ISP’s or company’s mail server. • Emails are sent using the simple mail transfer protocol (SMTP) • In order to determine the recipient’s mail server, a DNS mail exchange (MX) query is issued to the local DNS server for that domain name 5 Electronic Mail outgoing message queue user mailbox user agent Three major components: user agents mail servers mail server simple mail transfer protocol: user agent SMTP mail server SMTP User Agent SMTP a.k.a. “mail reader” composing, editing, reading mail messages © 2002 Huhns • user agent SMTP user agent mail server e.g., Eudora, Outlook, elm, user agent Mozilla Thunderbird outgoing, incoming messages stored on server user agent 6 • Mail Servers mailbox contains incoming messages for user message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages client: sending mail server “server”: receiving mail server user agent mail server user agent SMTP mail server SMTP © 2002 Huhns Electronic Mail: mail servers user agent SMTP user agent mail server user agent user agent 7 Electronic Mail: SMTP [RFC 2821] port 25 direct transfer: sending server to receiving server three phases of transfer handshaking (greeting) transfer of messages closure © 2002 Huhns uses TCP to reliably transfer email message from client to server, command/response interaction commands: ASCII text response: status code and phrase messages must be in 7-bit ASCII 8 • 4) SMTP client sends Alice’s message over the TCP connection • 5) Bob’s mail server places the message in Bob’s mailbox • 6) Bob invokes his user agent to read message • 1) Alice uses UA to compose message and “to” bob@someschool.edu • 2) Alice’s UA sends message to her mail server; message placed in message queue • 3) Client side of SMTP opens TCP connection with Bob’s mail server 1 user agent 2 mail server 3 mail server 4 6 5 © 2002 Huhns Scenario: Alice sends message to Bob user agent 9 SMTP • A sender-SMTP establishes a two-way transmission channel to a receiver-SMTP on PORT 25 • HELO command “HELO engr.sc.edu” • MAIL command “MAIL <SP> FROM: address<CRLF>” • RCPT command “RCPT <SP> TO: address<CRLF>” • DATA command • End-of-mail indicator • QUIT © 2002 Huhns Simple Mail Transfer Protocol 10 USER 1 Sender – SMTP mailbox.engr.sc.edu © 2002 Huhns Architectural View of SMTP SMTP Commands/Replies PORT 25 USER 2 Receiver – SMTP Hotmail.com 11 S: C: S: C: S: C: S: C: S: C: C: C: S: C: S: 220 hamburger.edu HELO crepes.fr 250 Hello crepes.fr, pleased to meet you MAIL FROM: <alice@crepes.fr> 250 alice@crepes.fr... Sender ok RCPT TO: <bob@hamburger.edu> 250 bob@hamburger.edu ... Recipient ok DATA 354 Enter mail, end with "." on a line by itself Do you like ketchup? How about pickles? . 250 Message accepted for delivery QUIT 221 hamburger.edu closing connection © 2002 Huhns Sample SMTP interaction 12 Mail message format SMTP: protocol for exchanging email msgs • RFC 822: standard for text message format: header lines, e.g., To: From: Subject: different from SMTP commands! body the “message”, ASCII characters only header © 2002 Huhns • blank line body 13 Message format: multimedia extensions additional lines in msg header declare MIME content type Types: Uuencode, base64, Quoted-printable MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg © 2002 Huhns MIME: multimedia mail extension, RFC 2045, 2056 base64 encoded data ..... ......................... ......base64 encoded data 14 © 2002 Huhns MIME 15 SMTP SMTP user agent sender’s mail server receiver’s mail server SMTP: delivery/storage to receiver’s server Mail access protocol: retrieval from server access protocol user agent © 2002 Huhns Mail access protocols 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: gmail, Hotmail, Yahoo! Mail, etc. 16 • telnet servername 25 • see 220 reply from server • enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) © 2002 Huhns Try SMTP interaction for yourself: 2117 SMTP: final words Comparison with HTTP: • HTTP: pull • SMTP: push © 2002 Huhns • SMTP uses persistent connections • SMTP requires message (header & body) to be in 7-bit ASCII • SMTP server uses CRLF.CRLF to determine end of message • both have ASCII command/response interaction, status codes • HTTP: each object encapsulated in its own response msg • SMTP: multiple objects sent in multipart msg 2118 POP3 • POP3 is used to receive email messages via a TCP/IP connection; a client establishes a connection with a POP3 server at PORT 110 © 2002 Huhns Post-Office Protocol • Authorization state USER huhns PASS ***** • Transaction state STAT +OK <SP> # of messages <SP> size of mailbox • Retrieve command RETR 45 Response: Header <CRLF> Message content • DELE msg# & RSET 19 • authorization phase client commands: user: declare username pass: password server responses +OK -ERR transaction phase, client: list: list message numbers retr: retrieve message by number dele: delete quit S: C: S: C: S: +OK POP3 server ready user bob +OK pass hungry +OK user successfully logged on © 2002 Huhns POP3 protocol C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off 20 • More about POP3 Previous example uses “download and delete” mode. Bob cannot re-read e-mail if he changes client “Download-and-keep”: copies of messages on different clients POP3 is stateless across sessions • IMAP Keep all messages in one place: the server Allows user to organize messages in folders IMAP keeps user state across sessions: names of folders and mappings between message IDs and folder name © 2002 Huhns POP3 (more) and IMAP 21 /*********** After Connection ************/ +OK Microsoft Exchange POP3 server version 5.5.2654.50 ready /* SERVER */ USER shroff /* CLIENT */ +OK /* SERVER */ PASS ********** /* CLIENT */ +OK User successfully logged on /* SERVER */ STAT /* CLIENT */ +OK 107 1545500 /* SERVER */ RETR 107 /* CLIENT */ +OK /* SERVER */ /* HEADER, BLANK LINE, CONTENT */ Received: from imo-m03.mx.aol.com ([64.12.136.6]) by mailbox.engr.sc.edu with SMTP From: Hm412000@aol.com Date: Tue, 18 Sep 2001 00:06:54 EDT Subject: Re: CSCE826 Homework To: HUHNS@engr.sc.edu I finished assignment two … . © 2002 Huhns Example POP3 Interaction 22 /** PERIOD **/ Example SMTP Interaction © 2002 Huhns /*********** After Connection ************/ 220 theusc.csd.sc.edu ESMTP Sendmail 8.9.0/8.9.0; Mon, 24 Sep 2001 00:58:05 –0400 /* SERVER */ HELO engr.sc.edu /* CLIENT */ 250 theusc.csd.sc.edu Hello l-1d11-14.engineering [129.252.26.88] pleased to meet you /* SERVER */ MAIL FROM: stephens@engr.sc.edu /* CLIENT */ 250 stephens@engr.sc.edu... Sender ok /* SERVER */ RCPT TO: huhns@engr.sc.edu /* CLIENT */ 250 stephens@engr.sc.edu... Recipient ok /* SERVER */ Data /* CLIENT */ 354 Enter mail, end with "." on a line by itself /* SERVER */ Date: Mon Sep 24 01:00:53 EDT 2001 /* CLIENT */ From: stephens@engr.sc.edu Subject: result for your query any old message . 250 AAA33192 Message accepted for delivery QUIT /* PERIOD Signaling End-of-Message */ /* SERVER */ /* CLIENT */ 23 © 2002 Huhns POP3 and SMTP 24 Database Application receives and sends email Application USER 1DB 2Txt File 3Word Doc 4ExcelSheet 5HTML 6Image 7Directory SpreadSheet © 2002 Huhns Service Example: Data and Document Access Files Directory 25 • The service application receives messages sent by “USER” • “USER” specifies file type in SUBJECT field © 2002 Huhns Data and Document Access (cont.) • E.g., DIR, HTML, DB, ALL (for file listing), etc. • “USER” specifies name of file, query, or command in CONTENT field • Application returns results either as email content or attachment 26 • SMTP is used to send emails from client to server. • POP3 is used to receive emails from server to client. • POP3 can be used to delete emails from the server once received. © 2002 Huhns Conclusion 27