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

Post on 08-Jul-2020

3 views 0 download

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

Concept of Mail Protocols

bdNOG7,Dhaka.

Format of an Email

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

Local part defines user mailbox and domain name mention the destination

Local_address@domainname.tld

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

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.

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.

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

Mail Delivery Agent(MDA)

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.

SMTP Mail transfer Flow

MTA connection setup

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

SMTP Exchange of command response pair

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 (.)

MTA connection termination

MTA connection terminationSender sends QUIT and waits for reply

Then initiate TCP close operation

Receiver initiates TCP close after sending reply to QUIT

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

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

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

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

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)

SMTP status codes..Cont.

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]

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)

POP3 ConnectionEstablishment

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 user@testing.com+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.

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

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 user@testing.com letmein A1 OK Logged in.A2 SELECT Inbox* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)*

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.

Webmail

MIME(Multipurpose Internet Mail Extensions)

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

Email header with MIME [RFC 2045]

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

MIME 1.1