SMTP basics - What is SMTP?

September 8, 2007

Overview

The SMTP protocol is a simple text based set of rules that establish how two mail servers communicates between. It is a 2 way communication as stated in RFC 821 : “as the result of a user mail request, the sender-SMTP establishes a two-way transmission channel to a receiver-SMTP. The receiver-SMTP may be either the ultimate destination or an intermediate. SMTP commands are generated by the sender-SMTP and sent to the receiver-SMTP. SMTP replies are sent from the receiver-SMTP to the sender-SMTP in response to the commands.

How does it work more exactly?

A basic email session starts by connecting to the server and is basically a set of pairs message/response between sender/receiver. The SMTP communication can be directly between the two servers or can relay through a third one. The RFC 821 describe the way relaying works like this: ” To be able to provide the relay capability the SMTP-server must be supplied with the name of the ultimate destination host as well as the destination mailbox name.

The argument to the MAIL command is a reverse-path, which specifies who the mail is from. The argument to the RCPT command is a forward-path, which specifies who the mail is to. The forward-path is a source route, while the reverse-path is a return route (which may be used to return a message to the sender when an error occurs with a elayed message)”

There are three steps into the SMTP procedure

  • MAIL

The MAIL step is basically how an e-mail is being sent. This is how a MAIL session may look

	         S: MAIL FROM:<sender@assistprogramming.com>
                 R: 250 OK

                 S: RCPT TO:<receiver1@assistprogramming.com>
                 R: 250 OK

                 S: RCPT TO:<receiver2@assistprogramming.com>
                 R: 550 No such user here

                 S: RCPT TO:<receiver3@assistprogramming.com>
                 R: 250 OK

                 S: DATA
                 R: 354 Start mail input; end with <CRLF>.<CRLF>

                 S: Here is the first line of the mail input
                 S: ...etc. etc. etc.
                 S: <CRLF>.<CRLF>
                 R: 250 OK

This could be a standard MAIL session that tries to send message from sender@… to receiver1, receiver2 and receiver3. We can see that receiver2 does not exists. The SMTP protocols has some response codes that are always standard. A full list of them can be found on the RFC 821 implementation. Each code can be followed by a textual message which intents to give a descriptive of the code. The response textual messages can differ from server to server( QMail has some messages, Exim others and so on) .

  • FORWARDING

There are some cases where the destination information in the <forward-path> is incorrect, but the receiver-SMTP knows the correct destination. In such cases, one of the following replies should be used to allow the sender to contact the correct
destination.

  • 251 User not local; will forward to <forward-path>
  • 551 User not local; please try <forward-path>

Example:

      S: RCPT TO:<Postel@USC-ISI.ARPA>
      R: 251 User not local; will forward to <Postel@USC-ISIF.ARPA>
  • VERIFYING AND EXPANDING

            S: VRFY claude
                      R: 250 Fred claude <claudiu@assisprogramming.com>

         Or

            S: VRFY test
            R: 251 User not local; will forward to <test@assistprogramming.com>

         Or

            S: VRFY user
            R: 550 String does not match anything.

         Or

            S: VRFY user1
            R: 551 User not local; please try <user4@assitprogramming.com>

         Or

            S: VRFY hkhjkghj
            R: 553 User ambiguous.

 

Post a comment

Name (required)

Mail (will not be published) (required)

Website

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word