SMTP and POP3:
Communicating with
email Servers
Defiani Ar둰anildy,둰 M.Si 0818 0296 4763
deff_i둰anildy,yy,i૰oo.cooy
©
2
0
0
2
H
u
૰
an
s
Overview
•
Se둰vicoe vii Eyiil
•
Seandiang Eyiil
•
SMTP
•
POP3
•
Coancolusioan
©
2
0
0
2
H
u
૰
an
s
Services via Email
•
Eyiil is ian Iante둰anet ipplicoitioan t૰it is
iviilible widely,: it coian be icocoessed
f둰oy liptops둰 desktops둰 PDArs둰 yobile
p૰oanes둰 iand pige둰s
•
Iyigiane ian ipplicoitioan t૰it coian 둰ecoeive
eyiil f둰oy i use둰둰 pe둰fo둰y t૰e se둰vicoes
둰equested by, o둰 oan be૰ilf of t૰e use둰둰
iand t૰ean seand t૰e 둰esults bicok to t૰e
use둰 vii eyiil
•
T૰e ipplicoitioan uses t૰e SMTP iand
POP3 p둰otocools
©
2
00
2
H
uh
ns
Sending an email
•
Eve둰y, eyiil yust ૰ive i destianitioan eyiil
idd둰ess. Aran eyiil idd둰ess tikes t૰e followiang
fo둰y:
•
T૰e doyiian aniye ian ian eyiil idd둰ess geane둰illy,
does anot iancolude t૰e “www” p둰efx둰 w૰ico૰ is
cooyyoan fo둰 Web site idd둰esses
©
2
0
0
2
H
u
૰
an
s
•
Eyiils i둰e anot iyyediitely, delive둰ed to t૰e
둰ecoipieant; iansteid둰 t૰ey, i둰e ianitiilly, seant to y,ou둰
ISP’s o둰 cooypiany,’s yiil se둰ve둰.
•
Eyiils i둰e seant usiang t૰e siyple yiil t둰iansfe둰
p둰otocool (SMTP)
•
Ian o둰de둰 to dete둰yiane t૰e 둰ecoipieant’s yiil se둰ve둰둰 i
DNS yiil exco૰iange (MX) que둰y, is issued to t૰e
locoil DNS se둰ve둰 fo둰 t૰it doyiian aniye
©
2
0
0
2
H
u
૰
an
s
Electronic Mail
• Three major components: user agents
mail servers
simple mail transfer protocol:
SMTP
User Agent
a.k.a. “mail reader”
composing, editing, reading mail
messages
e.g., Eudora, Outlook, elm,
Mozilla Thunderbird
outgoing, incoming messages
stored on server 6
Electronic Mail: mail servers
• 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
Electronic Mail: SMTP
[RFC 2821]
uses TCP to reliably transfer email message from client to server,
port 25
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
messages must be in 7-bit ASCII
8
©
2
0
0
2
H
u
૰
an
Scenario: Alice sends message to
Bob
• 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
• 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
SMTP
Simple Mail Transfer Protocol
•
Ar seande둰-SMTP estiblis૰es i two-wiy,
t둰iansyissioan co૰iananel to i
둰ecoeive둰-SMTP oan PORT 25
•
HELO cooyyiand “HELO eang둰.sco.edu”
•
MArIL
cooyyiand
“MArIL <SP> FROM: idd둰ess<CRLF>”
•
RCPT
cooyyiand
“RCPT
<SP>
TO:
idd둰ess<CRLF>”
•
DArTAr cooyyiand
•
Eand-of-yiil iandicoito둰
•
QUIT
©
2
00
2
H
uh
ns
Architectural View of
SMTP
©
2
00
2
H
uh
ns
11
USER 1
Sender – SMTP
mailbox.engr.sc.edu
Receiver – SMTP
Hotmail.com
SMTP Commands/Replies PORT 25
Sample SMTP interaction
12 S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu>
S: 250 bob@hamburger.edu ... Recipient ok C: DATA
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 C: QUIT
S: 221 hamburger.edu closing connection
©
2
0
0
2
H
u
૰
an
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
body
blank line
©
2
0
0
2
H
u
૰
an
s
Message format: multimedia extensions
MIME: yultiyedii yiil exteansioan둰 RFC 2045둰 2056 idditioanil lianes ian ysg ૰eide둰 decoli둰e MIME cooanteant
ty,pe
Ty,pes: Uueancoode둰 bise64둰 Quoted-p둰iantible
14
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
base64 encoded data ... ... ...base64 encoded data
multimedia data type, subtype, parameter declaration method used to encode data MIME version
encoded data
©
2
0
0
2
H
u
૰
an
15
MIME
©
2
0
0
2
H
u
૰
an
Mail access protocols
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: gmail, Hotmail, Yahoo! Mail, etc.
user agent
sender’s mail server user
agent
SMTP SMTP access
protocol
receiver’s mail
server ©
2
0
0
2
H
u
૰
an
s
Try SMTP interaction for yourself:
•
telnet servername 25
•
see 220 둰eply, f둰oy se둰ve둰
•
eante둰 HELO둰 MArIL FROM둰 RCPT TO둰 DArTAr둰 QUIT
cooyyiands
ibove lets y,ou seand eyiil wit૰out usiang eyiil
colieant (둰eide둰)
21-17
©
2
0
0
2
H
u
૰
an
SMTP: fnal words
• SMTP uses pe둰sisteant
cooananecotioans
• SMTP 둰equi둰es yessige
(૰eide둰 & body,) to be ian 7-bit ArSCII
• SMTP se둰ve둰 uses
CRLF.CRLF to dete둰yiane
eand of yessige
Coypi둰isoan wit૰
HTTP:
• HTTP: pull • SMTP: pus૰
• bot૰ ૰ive ArSCII
cooyyiand/둰espoanse
iante둰icotioan둰 stitus coodes
• HTTP: eico૰ objecot
eancoipsulited ian its owan 둰espoanse ysg
• SMTP: yultiple objecots seant ian yultipi둰t ysg
21-18
©
2
0
0
2
H
u
૰
an
POP3
Post-Ofice Protocol
•
POP3 is used to 둰ecoeive eyiil yessiges vii i
TCP/IP cooananecotioan; i colieant estiblis૰es i
cooananecotioan wit૰ i POP3 se둰ve둰 it PORT 110
• Arut૰o둰izitioan stite USER ૰u૰ans
PArSS *****
• T둰iansicotioan stite STArT
+OK <SP> # of yessiges <SP> size of yiilbox
•
Ret둰ieve cooyyiand
RETR 45
Respoanse: Heide둰 <CRLF> Messige cooanteant
•
DELE ysg# & RSET
©
2
00
2
H
uh
ns
POP3 protocol
•
iut૰o둰izitioan p૰ise
colieant cooyyiands:
user: decoli둰e use둰aniye pass: pisswo둰d
se둰ve둰 둰espoanses
+OK -ERR
t둰iansicotioan p૰ise둰
colieant: list: list yessige anuybe둰s retr: 둰et둰ieve yessige by,
S: +OK POP3 server ready C: user bob
S: +OK
C: pass hungry
S: +OK user successfully logged on
POP3 (more) and IMAP
• 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
21
©
2
0
0
2
H
u
૰
an
Example POP3 Interaction
/*********** Arfte둰 Coananecotioan ************/
+OK Mico둰osoft Exco૰iange POP3 se둰ve둰 ve둰sioan 5.5.2654.50 둰eidy, /* SERVER */
USER s૰둰off /* CLIENT */
+OK /* SERVER */
PArSS ********** /* CLIENT */
+OK Use둰 sucocoessfully, logged oan /* SERVER */
STArT /* CLIENT */
+OK 107 1545500 /* SERVER */
RETR 107 /* CLIENT */
+OK /* SERVER */
/* HEArDER둰 BLArNK LINE둰 CONTENT */
Recoeived: f둰oy iyo-y03.yx.iol.cooy ([64.12.136.6]) by, yiilbox.eang둰.sco.edu wit૰ SMTP
F둰oy: Hy412000yiol.cooy
Dite: Tue둰 18 Sep 2001 00:06:54 EDT Subjecot: Re: CSCE826 Hoyewo둰k
To: HUHNSyeang둰.sco.edu
I fanis૰ed issiganyeant two …
. /** PERIOD **/
©
2
00
2
H
uh
ns
Example SMTP Interaction
/*********** Arfte둰 Coananecotioan ************/
220 t૰eusco.cosd.sco.edu ESMTP Seandyiil 8.9.0/8.9.0; Moan둰 24 Sep 2001 00:58:05 – 0400 /* SERVER */
HELO eang둰.sco.edu /* CLIENT */
250 t૰eusco.cosd.sco.edu Hello l-1d11-14.eangianee둰iang [129.252.26.88] pleised to yeet y,ou /* SERVER */
MArIL FROM: step૰eansyeang둰.sco.edu /* CLIENT */
250 step૰eansyeang둰.sco.edu... Seande둰 ok /* SERVER */ RCPT TO: ૰u૰ansyeang둰.sco.edu /* CLIENT */
250 step૰eansyeang둰.sco.edu... Recoipieant ok /* SERVER */ Diti /* CLIENT */
354 Eante둰 yiil둰 eand wit૰ "." oan i liane by, itself /* SERVER */ Dite: Moan Sep 24 01:00:53 EDT 2001 /* CLIENT */
F둰oy: step૰eansyeang둰.sco.edu Subjecot: 둰esult fo둰 y,ou둰 que둰y,
iany, old yessige
. /* PERIOD Siganiliang Eand-of-Messige */
250 ArArAr33192 Messige icocoepted fo둰 delive둰y, /* SERVER */ QUIT /* CLIENT */
©
2
00
2
H
uh
ns
24
POP3 and SMTP
©
2
0
0
2
H
u
૰
an
Service Example: Data and Document
Access
©
2
00
2
H
uh
ns
25
USER
Application
1DB 2Txt File 3Word Doc 4ExcelSheet 5HTML 6Image 7Directory
Database
SpreadSheet
Files
Directory
Data and Document Access (cont.)
•
T૰e se둰vicoe ipplicoitioan 둰ecoeives
yessiges seant by, “USER”
•
“USER” specoifes fle ty,pe ian SUBJECT
feld
•
E.g.둰 DIR둰 HTML둰 DB둰 ArLL (fo둰 fle listiang)둰 etco.
•
“USER” specoifes aniye of fle둰 que둰y,둰 o둰
cooyyiand ian CONTENT feld
•
Arpplicoitioan 둰etu둰ans 둰esults eit૰e둰 is
eyiil cooanteant o둰 ittico૰yeant
©
2
00
2
H
uh
ns
Conclusion
•
SMTP is used to seand eyiils f둰oy colieant to se둰ve둰.
•
POP3 is used to 둰ecoeive eyiils f둰oy se둰ve둰 to
colieant.
•
POP3 coian be used to delete eyiils f둰oy t૰e
se둰ve둰 oancoe 둰ecoeived.
©
2
0
0
2
H
u
૰
an
s