Sending and Receiving Mails
• SMTP (Simple Mail Transfer Protocol)
• POP3 (Post Office Protocol version 3)
• IMAP4 (Internet Message Access Protocol version 4)
• MIME (Multipurpose Internet Mail Extension)
SMTP RFCs
• RFC 821: Simple Mail Transfer Protocol
• Related RFCs – RFC 822 (Standard for the format of ARPA Internet text messag
es)– RFC 1521 (MIME)– RFC - 1725 (POP3)– RFC - 1730 (IMAP4)
• Well known port : 25 (TCP)
ESMTP
• Extended Simple Mail Transfer Protocol• RFC 1869: SMTP Service Extensions• RFC 1870: SMTP Service Extension for Messa
ge Size Declaration• RFC 1891: SMTP Service Extension for Delive
ry Status Notifications• RFC 2554: SMTP Service Extension for Authe
ntication • Two major differences from SMTP:
1. Support 8-bit MIME encoding2. Support SMTP authorization
SMTP: Simple Mail Transfer Protocol
• Three Components: –user agents: “mail readers”
–mail servers: “mailbox; mail queue”
–smtp: simple mail transfer protocol• protocol between mail servers• protocol between mail the server and the clie
nt
SMTP: agents/servers• user agents: “mail readers”
– composing, editing, reading mail messages– e.g., Outlook, Eudora, pine, elm, Netscape
Messenger– send and receive outgoing and incoming messages
to mail server
• mail servers:– mailbox: contains incoming messages (yet to be
read) for user– message queue: contains outgoing (to be sent) mail
messages
SMTP Process
• Contact server on well known port (25)• ASCII oriented command/response• methodology
– contact server– wait for greeting– send HELO
– wait for response – send command– wait for response– repeat last two
SMTP Commands
• HELP– identifies the client to the server, fully qualified domain name, onl
y sent once per session
• MAIL– initiate a message transfer, fully qualified domain of originator
• RCPT– follows MAIL, identifies an addressee, typically the fully qualified
name of the addressee – for multiple addressees use one RCPT for each addressee
• DATA– send data line by line– <cr>.<cr> tells server data transfer is over
SMTP Commands
• RSET– tells server to abort current message and clear all of it buffers– same state as after HELO
• SEND , SOML , SAML– like MAIL, outdated not used any more
• VRFY– ask server to verify a user name– server replies positively of it knows user, negatively if not
• EXPN– ask server to confirm mailing list alias– server reply is multi-line, one per user
SMTP Commands
• HELP– ask server for help
• by itself get a list of server supported commands
• <string> get help for that command
• NOOP– ask server to respond with a positive reply
• QUIT– tell server that client is ending session– server replies positively and closes connection
• TURN– reverse roles of client and server
• outdated, rarely used on modern internet
Reply codes• 211 - System status or help ready• 214 - Help message• 220 - <domain> Service ready• 221 - <domain> Service closing transmission channel• 250 - Requested mail action OK, ready• 251 - User not local, will forward to <forward path>• 354 - Start mail input; end with <crlf>.<crlf>• 421 - <domain> Service not avail, closing transmission channel• 450 - Requested mail action not taken, mailbox not available• 451 - Requested action aborted, local error• 452 - Requested action not taken, insufficient storage• 500 - Syntax error, command unrecognized• 501 - Syntax error in parameters• 502 - Command not implemented• 503 - Bad sequence of commands• 504 - Command Parameter not implemented
Reply codes (more)• 550 - Requested action not taken, mailbox unavailable• 551 - User not local, please try <forward path>• 552 - Requested mail action not taken; exceeded storage allocation• 553 - Requested action not taken, mailbox name not allowed• 554 - Transaction failed
Reply Code (more)
353
Indicates success,
failure, or incomplete
The category of error message
The specific message for
that category
SMTP: Example• telnet smtp.csie.ncu.edu.tw 25
– 220 relay2.csie.ncu.edu.tw ESMTP Sendmail 8.12.11/8.12.11; Thu, 11 Mar 2004 09:54:23 +0800 (CST)220 mailServer.iitb.edu
• helo smtp.csie.ncu.edu.tw– 250 relay2.csie.ncu.edu.tw Hello adsl-211-78-177-115.HCON.sparq
net.net [211.78.177.115], pleased to meet you
• mail from:[email protected]– 250 2.1.0 [email protected]... Sender ok
• rcpt to:[email protected]– 550 5.7.1 [email protected]... Relaying denied. Proper
authentication required.• rcpt to:[email protected]
– 250 2.1.5 [email protected]... Recipient ok
SMTP: Example (more)• data
– 354 Please start mail input.• date:
subject: This is a test.from: [email protected]: [email protected]: [email protected], JRThis is a test..– 250 Mail queued for delivery.
• quit– 221 Closing connection. Good bye.
ESMTP: Example• telnet smtp.csie.ncu.edu.tw 25
– 220 relay2.csie.ncu.edu.tw ESMTP Sendmail 8.12.11/8.12.11; Thu, 11 Mar 2004 09:54:23 +0800 (CST)220 mailServer.iitb.edu
• ehlo smtp.csie.ncu.edu.tw– 250-relay2.csie.ncu.edu.tw Hello adsl-211-78-177-115.HCON.sparq
net.net [211.78.177.115], pleased to meet you– 250-ENHANCEDSTATUSCODES– 250-PIPELINING– 250-8BITMIME– 250-SIZE– 250-DSN– 250-ETRN– 250-AUTH LOGIN PLAIN– 250-STARTTLS– 250-DELIVERBY– 250 HELP
ESMTP: Example• help
– 214-2.0.0 This is sendmail version 8.12.11– 214-2.0.0 Topics:– 214-2.0.0 HELO EHLO MAIL RCPT DATA– 214-2.0.0 RSET NOOP QUIT HELP VRFY– 214-2.0.0 EXPN VERB ETRN DSN AUTH– 214-2.0.0 STARTTLS– 214-2.0.0 For more info use "HELP <topic>".– 214-2.0.0 To report bugs in the implementation send email to– 214-2.0.0 [email protected].– 214-2.0.0 For local information send email to Postmaster at your
site.– 214 2.0.0 End of HELP info
Mail message format
• RFC 822: Standard for the format of ARPA Internet text messages
• header lines:– Date:– From:– To:– Reply-to:– Subject:– etc...
Multimedia extensions• additional lines in message header declare
MIME content type
From: [email protected] To: [email protected] Subject: Picture. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg
base64 encoded data ..... ......................... ......base64 encoded data .
multimedia datatype, parameter declaration
method usedto encode data
MIME version
encoded data
MIME [RFC 2045, 2056]
• MIME: Multimedia Extension Types:– Text: subtypes: plain, html
– Image: subtypes: jpeg, gif
– Audio: subtypes: basic (8-bit mu-law encoded), 32kadpcm (32 kbps coding)
– Video: example subtypes: mpeg, quicktime– Application: other data that must be processed by read
er before “viewable”; example subtypes: msword, octet-stream
POP3
• POP3(Post Office Protocol 3) defined RFC1939• Used TCP port 110• No state information between client and the mail server• Client side mail management• No security
• POP3 progresses through three phases– Authorization – user / pass– Transaction – list / retr / dele / stat– Update – quit
• Two Operation modes– Download-and-delete mode– Download-and-keep keep
POP3 Commands
• USER name valid in the AUTHORIZATION state• PASS string• QUIT
• STAT valid in the TRANSACTION state• LIST [msg]• RETR msg• DELE msg• NOOP• RSET
• QUIT valid in the UPDATE state
POP3 Replies
• +OK
• -ERR
POP3Hamburger</home/staff/hkkim>9% telnet rtlab.skku.ac.kr 110Trying 61.72.102.32...Connected to rtlab.skku.ac.kr.Escape character is '^]'.+OK Qpopper (version 4.0.3) at imtl.skku.ac.kr starting. user hkkim+OK Password required for hkkim.pass tlftlrks+OK hkkim has 3 visible messages (0 hidden) in 3043 octets.list+OK 3 visible messages (3043 octets)1 14832 7803 780.retr 1+OK 1483 octetsReceived: from brunhild ([10.51.12………3 780.dele 1+OK Message 1 has been delted.quit+OK Pop server at imtl.skku.ac.kr signing off.Connection closed by foreign host.
Download-and-delete
Authorization
Transaction
Update
Term project problems
• Design a sending mail program supporting ESMTP AUTH
• Design a receiving mail program supporting MIME