Guide to SMTP (Simple Mail Transfer Protocol)

Guide to SMTP (Simple Mail Transfer Protocol)

    Email is by far the most popular service on the Internet. It puts you in contact with your friends and business relatives in just seconds. To be able to send email to your contacts, you need an email client on your machine that talks to a mail server that will route the email to the mail server where the recipients mailbox is stored. The way mail servers talk to each other is by using a standard protocol called SMTP - short for Simple Mail Transfer Protocol. This guide will cover the aspects of the SMTP protocol, email server, routing and how these systems work.

SMTP Email flow

    When you send an email your client uses SMTP to transmit the email to your outbound server. This is like putting a letter into a postbox or post office for delivery.

    Email client SMTP SMTP Server
    Email client SMTP SMTP Server

    The smtp server then looks up the correct server to deliver the email to based on the email domain and sends the email on to the next server, again using the SMTP protocol.

    SMTP Server SMTP Mail Server
    SMTP Server SMTP Mail Server

    The mailserver responsible for the email recipient domain then stores the email ready for the recipient's email client to collect it. This is similar to putting the email in a pigeon-hole for the recipient.

    Mail Server POP3/IMAP Recipient client
    Mail Server POP3/IMAP Recipient client

    The recipient collects the email from the mailserver using a mail client that users the protocol POP3 or IMAP (or webmail using a web browser)




How does it work?


    When you create an email in your email program, the message is sent to a mail server that allows you to send emails. Your email client will be configured to send all it's outgoing emails to this server. In most cases this is done by using the SMTP protocol. What happens next?
  • Your server then looks at the envelope (just as the post office would do with a normal letter) and looks to whom the email is addressed. Let's use user@example.com in our example.

  • Your server then needs to find out where to send the email. Based on the recipients domain name (the name to the right of the @-sign. i.e: example.com), it needs to

  • do a DNS (Domain Name Server) lookup. It will look in DNS to find the MX (Mail eXchange) entry for the domain example.com. This gives your email server the IP address/hostname of the mail server that is responsible for receving emails for the domain example.com.

  • When your server knows the IP address (destination) of your recipients email server, it will do a connect to this server on the SMTP port. The port used on the internet is ALWAYS port 25 for SMTP.

  • When connected, your server will say "Hello, I have an email for 'user@example.com'". The email server at example.com then says "OK, please start the transmission of your email". If the server isn't responsible for receiving email for example.com, it will inform your server causing it to return the email with an error. These errors can happen when your server is using a DNS server that is not up-to date. It is therefore very important that your server uses correct DNS server(s).

  • Alternatively, your email server doesn't need to do the DNS/MX lookup if you have a smart host your server can forward all it's outbound emails to. A smart host will then either do the DNS/MX lookups itself, or forward the message to another server (smart host) to do the job. This is common in interal networks where you have a virus scanner that scans your outbound emails before delivery to the final destination.

    DIAGRAM SHOWING basically the flow of the SMTP email from
    client->server->dns lookup->remote server->delivery


Nice to know


  • On one machine (or to be exact, at one IP address), you can ONLY have one service that is bound to a specific internet port. I.e: In our terms, there can only be ONE server listening for SMTP traffic on TCP/IP port 25. However, you can have SMTP traffic running in your own network on other ports than 25 as long as the servers that are going to speak with each other knows about this.

  • The SMTP port used by ALL email systems that communicates with other public email servers on the internet is port 25. You cannot set your server to accept SMTP on another port if you want it to receive emails from the internet as your primary server.

  • A hostname/IP address is a unique address that identifies one machine on the internet.

  • DNS is a server hosted normally at your ISP (Internet Service Provider) to let other machines look up ip addresses of your domain.

  • 'Smart host' is a common name in email systems and describes another SMTP server that will be able to relay your messages. I.e: It could accept messages from your internal email server and then deliver it to the final destination. Your ISP will normally provide you with a smtp server you can use as smar thost.