smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 ·...

33
Concept of Mail Protocols bdNOG7,Dhaka.

Upload: others

Post on 08-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Concept of Mail Protocols

bdNOG7,Dhaka.

Page 2: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Format of an Email

Page 3: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Email AddressingA unique addressing system ,has two parts in addressing.

Local part defines user mailbox and domain name mention the destination

[email protected]

Email alias:Create a group email to send email to many people like multicast.

Page 4: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Email message fieldsHere are the meanings of the fields to be filled in when you send an email:

From: this is your email address;; most of the time you will not have to fill in this field, because it is generally set by the email client according to your preferences.

To: This field is used for the recipient's email address. Subject: this is the title that your recipients will see when they want to read the email Cc (carbon copy): this allows an email to be send to a large number of people by writing their respective addresses separated by

commas Bcc (blind carbon copy): This is a Cc, except that the recipient does not see the list of people in the Bcc field Message: This is the body of yourmessage

Other email functions are:

Attached Files, Attachments: A file can be attached to an email by specifying its location on the hard drive. Signature: If the email client allows it, you are often able to set a signature, meaning a few lines of text which will be added to the

end of the document.

Page 5: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Email DeliveryQueue

Unlike ftp/http it is not necessarily to deliver email in real time.Delivery not instantaneous ,It will wait in the queue of outgoing,incoming ,intermediate MTA message queue.

Page 6: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Component of Email system Mail Transport Agent/Message Transfer Agent (MTA) Mail User Agent (MUA)

Mail Delivery Agent(MDA)

Page 7: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MTAThe actual mail transfer is done through message transfer agents (MTAs). To send mail, a system must have the client MTA, and to receive mail, a system must have a server MTA. The formal protocol that defines the MTA client and server in the Internet is called Simple Mail Transfer Protocol (SMTP).

SMTP uses commands and responses to transfer mail between an MTA client and MTA server.

Page 8: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP Mail transfer Flow

Page 9: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MTA connection setup

Page 10: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MTA Connection Setup..Contd..Sender opens TCP connection with receiver Once connected, receiver identifies itself 220 service ready Sender identifies itself HELO <domain> Receiver accepts sender’s identification 250OK If mail service not available, step 2 above becomes: 421 service not available

Page 11: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP Exchange of command response pair

Page 12: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Message TransferSender may send one or more messages to receiver Each message transfer has the following phases: One MAIL command, identifies originator•Gives reverse path to use for error reporting•Receiver returns 250 OK or appropriate fail/error messageOne or more RCPT commands, identifies recipients for the message• Each recipient identified by a separate RCPT• Separate reply for each recipient (250 OK etc.) One DATA command transfers message text• End of message indicated by line containing just period (.)

Page 13: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MTA connection termination

Page 14: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MTA connection terminationSender sends QUIT and waits for reply

Then initiate TCP close operation

Receiver initiates TCP close after sending reply to QUIT

Page 15: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

OptimizationIf message is sent to multiple users on a given host,it is sent only once.

Delivery to users handled by destination host

If Multiple messages are ready for given host,a single TCP connection can be used.

Saves overhead of setting up and termination of connection

Page 16: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Possible Errors Host unreachable Host out of operation TCP connection fail during transfer Faulty destination address

User errorTarget user address has changed Redirect if possibleInform user if not

Sender re-­queue the mail -­ will retry till a configurable period of time

Page 17: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP protocol reliability TCP connection is used to transfer mail from sender to receiver over TCP

connection Attempts to provide reliable service No guarantee to recover lost messages No end-­to-­end ack to sender Error indication report not guaranteed

Page 18: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP receiver Accepts arriving message Places in user mailbox or copies to outbound message queue for forwarding Receivermust

verify local mail destination deal with errors Transmission Lack of disk space

Page 19: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP status codes(DSN-­Delivery status Notification)

Leading digits Indicates catagories

2XX-­Positive Completion Reply(Successful)

3XX-­Positive Intermediate Reply(Redirection)

4XX-­Transient negative completion reply(Client error)

5XX-­Permanent negative completion reply(Server error)

Page 20: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

SMTP status codes..Cont.

Page 21: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

POP3Mail access protocol:

POST OFFICE PROTOCOL [RFC 1939]

Simple and limited functionality,Consists of client software and Server software, Server performs user authorization

IMAP: Internet mail access protocol [Version 4]

Page 22: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

POP3Retrieves messages from a mail server

Typically, messages are downloaded to your mail client, and deleted from the server

Designed for use with dial-­up connections when people were intermittently connected

Listens on Port 110 (with Secure POP generally on port 995)

Page 23: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

POP3 ConnectionEstablishment

Page 24: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

POP3 protocol sessionroot@amberit ~]# telnet mail.amberit.com.bd 110 Trying 206.71.88.102...Connected to mail.amberit.com.bd. Escape character is '^]'.+OK Dovecot ready. user [email protected]+OKpass letmein+OK Logged in. list+OK 1messages:1 482.retr1+OK 482 octets<snip>MessageHeaders</snip>This is my short message quit+OK Logging out.

Page 25: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Basic POP3 commandsUSER <name> -­ identifies the user

PASS <password> -­ authentication for user STAT -­ lists all messages in the mailbox of user LIST <msg no.> -­ lists the content of a message RETR <msg no.> -­ retrieves a particular message DELE <msg no.> -­ Deletes a particular message NOOP RSET QUIT

Replies +OK–ERR

Page 26: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

IMAP Protocol session[root@amberit ~]# telnet mail.amberit.com.bd 143 Trying 206.71.88.102...

Connected to mail.amberit.com.bd Escape character is '^]'.* OK Dovecot ready.A1 LOGIN [email protected] letmein A1 OK Logged in.A2 SELECT Inbox* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)*

Page 27: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

IMAP Protocol session..cont.OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.* 1 EXISTS* 0 RECENT* OK [UIDVALIDITY 1225333589] UIDs valid* OK [UIDNEXT 2] Predicted next UIDA2 OK [READ-­WRITE] Select completed. A3 FETCH 1 BODY[HEADER]* 1 FETCH (BODY[HEADER] 454<snip> Message Header Delivered</snip> A3 OK Fetch completed.A4 LOGOUT* BYE LoggingoutA4 OK Logout completed. Connection closed by foreign host.

Page 28: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Webmail

Page 29: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MIME(Multipurpose Internet Mail Extensions)

Page 30: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MIMEMainmotivationSMTP can not transmit executables, images, audio/video clips, International characters (e.g. â, å, ä, è, é, ê, ë) that require 8-­bit ASCII etc.

MIME (Multipurpose Internet Mail Extensions) Allows other types of non-­text data to be carried by SMTP Encodes image, video clip, voice data as text data to betransmitted over SMTP RFC2045-­2049Defines new header fields, standardized content formats, and encodings to transfer them over mail

Page 31: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

Email header with MIME [RFC 2045]

Page 32: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MIME Email headerDefines five new message header fields:MIME-­Version: version no. Content-­Type: type of data in bodyContent-­transfer-­encoding: type of encoding used Content-­ID: uniquely identify MIME entityContent Description: plain text description of body

Page 33: smtp tutorial bdnog7wiki.bdnog.org/lib/exe/fetch.php/bdnog7/smtp_tutorial... · 2017-11-21 · EmailAddressing A"unique"addressing"system",hastwo"partsin addressing. Local&part&definesuser&mailboxand&domain&name&mention&the&destination&&

MIME 1.1