Upload
logan-mcdaniel
View
365
Download
0
Embed Size (px)
Citation preview
SMTP( 简单邮件传输协议 )
SIMPLE MAIL TRANSFER PROTOCOL
RFC 2812
Introdution
• standard e-mail protocol• part of the TCP/IP protocol• defines the message format and the message tr
ansfer agent (MTA)• TCP port 25• text-based protocol
Internet email system
• User agent• Mail server• SMTP
Some mail agents
• Microsoft Outlook• Foxmail• Netscape Messenger• Endora• Mail,pine,elm
Mail Server
• Core of email system• Mailbox• Message queue
SMTP
• SMTP was originally designed for only plain text (ASCII text)
• Provides reliable delivery of messages • Uses TCP and message exchange between client and s
erver • Other functions:
– E-mail address lookup – E-mail address verification
Scenario
SMTP Session
220 mail.cs.tcd.ie ESMTP Postfix (1.1.13)helo FooBarmail from: <[email protected]>250 Okrcpt to: <[email protected]>250 Okdata354 End data with <CR><LF>.<CR><LF>To: [email protected]: [email protected]: FooBarHello World.250 Ok: queued as A04537DB3quit221 Bye
SMTP commands
• HELO domainname startup and give your hostname MAIL• MAIL FROM: <sender-address> mail from this address • RECV TO: <recipient-address> send it to this address • VRFY address does this address actually exist (verify) • EXPN address expand this address • DATA start giving you the body of the mail message • RSET reset state and drop current mail message • NOOP do nothing • DEBUG [level] set debugging level • HELP give me some help please • QUIT close this connection
Telnet SMTP server
• telnet servername 25
Helo,mail from,rcpt to,data,crlf.crlf,quit
SMTP, HTTP
– Request/Reply protocols built on TCP or UDP– Designed to handle a fixed set of messages– Pull portocol and push protocol
Protocol Data Format ProgramsSMTP RFC 822 and MIME Pine, NSMail, Eudora,…HTTP HTML Explorer, Netscape, Opera
MIME: Multipurpose Internet Mail Extensions
• Consists of three parts1.Additional RFC822 Headers
• MIME-Version:• Content-Type:• Content-Transfer-Encoding:
2.Content types (and subtypes)• text/plain• text/rich• image/gif• application/postscript• Multipart/mixed; boundary=“…”
MIME Encoding
• Mail systems assume ASCII– Only 64 valid characters A-Z, a-z, 0-9, +, /
• Some datatypes include arbitrary binary data (e.g. JPEG)
• Base64 encoding– 3 bytes of data map to 4 ASCII Characters– A=0,B=1,…
• Also 7bit ASCII encoding– Human readable
Encoding of binary Data
8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1
0 00 000 11111 11111 1 1000 0 0 0
6 5 4 3 2 1
0 00 000 11111 11111 1 1000 0 0 0
6 5 4 3 2 16 5 4 3 2 16 5 4 3 2 1
base64 encoding
Treat every 3 bytes (24 bits) as 4 6-bit words
The Base64 Alphabet
Value Encoding Value Encoding Value Encoding Value Encoding0 A 17 R 34 i 51 z1 B 18 S 35 j 52 02 C 19 T 36 k 53 13 D 20 U 37 l 54 24 E 21 V 38 m 55 35 F 22 W 39 n 56 46 G 23 X 40 o 57 57 H 24 Y 41 p 58 68 I 25 Z 42 q 59 79 J 26 a 43 r 60 810 K 27 b 44 s 61 911 L 28 c 45 t 62 +12 M 29 d 46 u 63 /13 N 30 e 47 v14 O 31 f 48 w15 P 32 g 49 x16 Q 33 h 50 y
From: Steve Zdancewic <[email protected]>MIME-Version: 1.0To: [email protected]: Example MailContent-Type: multipart/mixed; boundary="------------020307000708030506070607"
This is a multi-part message in MIME format.--------------020307000708030506070607Content-Type: text/plain; charset=us-ascii; format=flowedContent-Transfer-Encoding: 7bit
This is the body.
--------------020307000708030506070607Content-Type: text/plain; name="example.txt"Content-Transfer-Encoding: 7bitContent-Disposition: inline; filename="example.txt"
Hello
--------------020307000708030506070607Content-Type: image/jpeg; name="doc.jpg"Content-Transfer-Encoding: base64Content-Disposition: inline; filename="doc.jpg"
/9j/4AAQSkZJRgABAQEASABIAAD//gAXQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04…
Mail Access Protocols
Pop3
• A simple mail access protocol
• RFC 1939
• Port 110• 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)
POP Commands
• USER - enter your user ID • PASS - enter your password • QUIT - quit the POP3 server • LIST - list the messages and their size • RETR - retrieve a message, pass it a message
number • DELE - delete a message, pass it a message
number • TOP - show the top x lines of a message, pass it
a message number and the number of lines
• list• 1 498• Retr 1• (…)• .• quit