electronic mail in the internet - york universityvlajic/4213/4213_17_smtp.pdf · electronic mail in...

19
1 Electronic Mail in the Internet Electronic Mail in the Internet Required reading: Kurose 2.4 CSE 4213, Fall 2006 Instructor: N. Vlajic

Upload: trinhnhu

Post on 05-Sep-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

1

Electronic Mail in the InternetElectronic Mail in the InternetRequired reading:

Kurose 2.4

CSE 4213, Fall 2006Instructor: N. Vlajic

2Electronic Mail

Electronic MailElectronic Mail – one of the first and most important Internet applications

• asynchronous applicationasynchronous application: the recipient of an e-mail messagedoes not have to be immediately available – he may collect the message at his own leisure

Electronic Mail SystemElectronic Mail System – consists of three major components:

• user agentuser agent – e-mail reader – allows user to readreply to, forward, save, and compose messages (examples: Eudora, Microsoft Outlook, pine, etc.)

• mail servermail server – core of e-mail infrastructure▪ always ‘on’▪ provides a mailboxmailbox for each user, where user’s

incoming mail is stored

▪ keeps all undelivered outgoing mail in messagemessagequeuequeue

• SMTP protocolSMTP protocol – enables delivery of e-mails fromsender to remote e-mail server

• mail access protocolmail access protocol – enables delivery of e-mailsover ‘last link’ – remote server to final recipient

mailservermail

server

useragentuseragentuseragent

useragentuseragentuseragent

useragentuseragentuseragent

mailservermail

servermail

server

useragentuseragentuseragent

useragentuseragentuseragent

mailservermail

servermail

server

useragentuseragentuseragent

SMTPSMTP

SMTPSMTP

SMTPSMTP

user mailbox

outgoing message queue

user

outgoing

3Electronic Mail (cont.)

EE--mail Deliverymail Delivery – 3-stage process:

SMTP clientrunning

over TCPTCP

SMTP serverrunning over TCPTCP, port 25port 25

STAGE 1: e-mail goes from user agent to local e-mail server▪ e-mail does not go directly to remote e-mail server as it may not be available at all times

STAGE 2: e-mail is relayed by local server (which now acts as SMTP clientSMTP client) to remote server (which is SMTP serverSMTP server in this stage)▪ SMTP server must be always running since e-mail can arrive at any time

STAGE 3: remote user agent uses a mail access protocol (e.g. POP3POP3 or IMAP4IMAP4) to accessmailbox and obtain mail

4

– to deliver mail, a mail handling system must use anaddressing system with unique addresses

• SMTP addresses consists of two parts: local partlocal part and domain namedomain name, separated by @

• local part defines the name of a special file (user mailbox)where all received mail for the given user is stored

• before sending e-mail out, mail server (i.e. SMTP client)makes a DNS query requesting MX recordMX record for recipient’sdomain name

• DNS server returns a list of mail exchange serversmail exchange servers thataccept incoming mail for that domain (e.g. postmaster@ …)

• sending server then attempts to establish an SMTPconnection to one of these servers

Electronic Mail (cont.)

EE--Mail AddressesMail Addresses

vlajic cs.yorku.ca

5Electronic Mail (cont.)

Example [ SMTP Message Transfer ]

mail server

DNS server

mail server

6SMTP

Simple Mail Simple Mail Transfer Protocol Transfer Protocol (SMTP)(SMTP)

– runs on top of TCP, to reliably deliver messages fromSMTP client to SMTP server

• transfer stepstransfer steps:(1) TCP handshaking(2) SMTP connection establishment(3) transfer of message(s)(4) SMTP connection termination(5) TCP closure

• SMTP uses special commandscommands and responses responses to transfermessages

• commands are sent from SMTP client to SMTP server – each command consists of a keyword followed by zero or morearguments

• responses are sent from SMTP server to SMTP client – eachresponse is a 3-digit code that may be followed by additionaltextual information

SMTPclient

SMTPserver

command

response

7SMTP (cont.)

SMTP CommandsSMTP Commands

Keyword Argument(s)

HELLO Sender’s host name.

MAIL FROM Sender of the message.

RCPT TO Intended recipient of the message.

DATA Body of the mail.

QUIT meaning: terminate message

RSET meaning: abort the current mail transactions

YRFY Name of recipient to be verified.

NOOP meaning: check the status of recipient

EXPN Mailing list to be expanded.

HELP Command name.

SEND FROM Intended recipient of the message.

SMOL FROM Intended recipient of the message.

SMAL FROM Intended recipient of the message.

8SMTP (cont.)

SMTP ResponsesSMTP Responses

Code Description

220 Service ready.

221 Service closing transmission channel.

354 Start mail input.

421 Service not available.

450 Mailbox not available.

500 Syntax error; unrecognized command.

501 Syntax error in parameters or arguments.

– 3-digit code that may be followed by additional textualinformation; the meaning of the 1st digit:

• 2yz2yz – requested command is successfully completed, anew command can be started

• 3yz3yz – requested command is accepted, but the recipientneeds more information before completion can occur

• 4yz4yz – requested command has been rejected, but theerror condition is temporary

• 5yz5yz – requested command is rejected and should not besend again

9SMTP (cont.)

SMTPclient

SMTPserver

Example [ SMTP Connection Establishment ]

(1) The client opens a TCP connection with the receiver.

(2) The server sends code 220 (service ready) to tell the client that it is ready to receive mail.If the server is not ready, it sends code 421.

(3) The client sends the HELO message to identify itself using its domain name address.

(4) The server responds with code 250 or some other code depending on the situation.

TCP

10SMTP (cont.)Example [ SMTP Message Transfer ]

(1) The client sends the MAIL FROM messageto introduce the sender of the message(mailbox + domain name)This step is needed to give the server thereturn mail address.

(2) The server responds with code 250.

(3) The client sends the RCPT message, whichincludes the mail address of the recipient.

(4) The server responds with code 250.

(5) The client sends the data message toinitialize the message transfer.

(6) The server responds with code 354.

(7) The client sends contents of the messagein consecutive lines. Each line is terminated by two-characters:carriage return + end of line.The message is terminated by a period.

(8) The server responds with code 250.

11SMTP (cont.)

Example [ SMTP Connection Termination ]

SMTPclient

SMTPserver

(1) The client sends the QUIT command.

(2) The server responds with code 221.

(3) The client initiates a TCP close operation.

If client has several messages to send, they all can be sentover the same TCP connection.

If client has several messages to send, they all can be sentIf client has several messages to send, they all can be sentover the same TCP connection.over the same TCP connection.

12Mail Message Formats and MIME

SMTP LimitationsSMTP Limitations – messages can be only sent in NVT 7-bit ASCII format• cannot be used for video or audio data, or for languages not

supported by 7-bit ASCII characters (French, Chinese, etc.)

MIMEMIME – Multipurpose Internet Mail Extensions (MIME)Multipurpose Internet Mail Extensions (MIME) – supplementary protocolthat allows non-ASCII data to be send through SMTP• not a mail protocol, cannot replace SMTP – only an extension to SMTP

• MIME transforms non-ASCII data at the sender site to NVT ASCII data and delivers it to the client SMTP to be sent through the Internet

• the SMTP server receives the NVT ASCII data and delivers it to MIME to betransformed back to the original data

13Mail Message Formats and MIME (cont.)

RFC 822RFC 822 – standard used for constructing messages for transmission via SMTP• messages = header + blank line + body

• header contains the info needed to accomplish transmission and delivery;body comprise the object to be delivered to the recipient

• header lines, e.g.,– To:– From:– Subject:

• body– the “message”, ASCII

characters only

header

body

blank line

RFC 2045 and 2046RFC 2045 and 2046 – extension to RFC 822 - defines additional MIME-relatedheader-lines required to send non-ASCII content• MIME-Version: current version is 1.1

• Content-Transfer-Encoding: defines the method to encodethe message into 0s and 1s for transport(e.g. 7-bit, 8-bit, binary, Base64, Quoted-printable)

• Content-Type: defines the type of data used in the body(e.g. plain, JPEG, GIF, MPEG) – allows receiving client to takean appropriate action, e.g. decompress/display a JPEG image

14Mail Message Formats and MIME (cont.)

From: [email protected]: [email protected]: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

multimedia datatype, subtype,

parameter declaration

method usedto encode data

MIME version

encoded data

Example [ MIME e-mail message ]

15Mail Message Formats and MIME (cont.)

Example [ Base64 encoding / decoding ]

USUS--ASCII character setASCII character set = { 32 non-printable, 96 printable char. } = { 128 characters }

Theory: each character can be encoded with 7-bitsPractice: each character is encoded with 8-bit (byte), where lower 7 bits represent

appropriate character and the 8th bit is set to 0

US-ASCII is a single-byte 7-bit character set.USUS--ASCII is a singleASCII is a single--byte 7byte 7--bit character set.bit character set.

European languages European languages (French, Danish, Spanish, …) have accentuated characters(é, ő, ñ). These languages employ character sets whose lower 7-bits (0-127) are identicalto US-ASCII, and the upper bit (128-255) is used to represent accentuated characters.

European languages employ single-byte 8-bit character sets.European languages employ singleEuropean languages employ single--byte 8byte 8--bit character sets.bit character sets.

Asian languages Asian languages have 100-s of characters, multiple bytes are needed to represent them.

Asian languages employ multiple-byte character sets.Asian languages employ multipleAsian languages employ multiple--byte character sets.byte character sets.

16

210zyx

wvuts

Code

63

62

61

60

59

58

57

56

55

Value

/+98

76543

Code

434241403938

3736353433

Value

rqponm

lkjih

Code

545352515049

4847464544

Value

VUTSRQ

PONML

Code

323130292827

2625242322

Value

gfedcb

aZYXW

Code

212019181716

1514131211

Value

KJIHGF

EDCBA

Code

910

678

34

5

210

Value

210zyx

wvuts

Code

63

62

61

60

59

58

57

56

55

Value

/+98

76543

Code

434241403938

3736353433

Value

rqponm

lkjih

Code

545352515049

4847464544

Value

VUTSRQ

PONML

Code

323130292827

2625242322

Value

gfedcb

aZYXW

Code

212019181716

1514131211

Value

KJIHGF

EDCBA

Code

910

678

34

5

210

Value

Mail Message Formats and MIME (cont.)

Base64Base64 – reversible encoding method that converts 8-bit data into 7-bit US-ASCII text.Base64 encoding:(1) divide the binary data into 24-bit blocks(2) divide each block into 4 sections (6-bit each)(3) interpret each 6-bit section as one US-ASCII character

SMTPSMTP – for historical reasons, SMTP is a 7-bit protocol, i.e. it limits byte of data sent to use only the lower-order 7-bits.When the transport layer provides a stream of bits to SMTP, each byte gets right justified with the most significant bit cleared to zero.

Radix-64 Encoding – 64 (26) printable characters

24-bit input

32-bit output

17Mail Message Formats and MIME (cont.)

3-byte to 4-byte coding is done for all data.The converted characters are then placed into the body of the message.Since Base64 characters are regular ASCII, they appear to SMTP like a ‘regular text message’. Entire message looks like gibberish to us.

http://www.rbl.jp/base64.php

What is the main drawback of Base64 method!?

18Mail Access Protocols

SMTP SMTP –– Push ProtocolPush Protocol – SMTP pushes the message from the sender to thereceiver even if the receiver does not want it

• TCP-SMTP connection is initiated by sender not receiver; thus SMTP is not suitable for 3rd stage of e-mail deliverywhere receiver may not be ‘on’ all times – hence, it pullsdata from mail server at its convenience

• most popular mail access protocols include Post OfficePost OfficeProtocolProtocol (POP) and Internet Mail Access ProtocolInternet Mail Access Protocol (IMAP)

• HTTP is an example of pull protocolpull protocol – TCP connection isinitiated by client interested in retrieving (pulling) data

19Mail Access Protocols (cont.)

POPPOP – simple protocol of rather limited functionality

Mail access starts with the user agentopening a TCP connection with the mail server on port 110port 110.

POP then progresses through 3 phases:authorization, transaction, update.

Phase 1: The user agent sends a username and password to authenticate theuser.

Phase 2: The user retrieves messages;also, the user can retrieve mail statisticsor mark messages for deletion.

Phase 3: The user issues QUIT command,ending the POP session; the server deletesthe messages that were marked for deletion.

TCP

POP serverTCP on port 110port 110