How Email Works
Email starts with the registrar through which the domain is purchased. When the domain is first created, the registrar has everything – website hosting, email hosting, and the domain name itself. This is because the registrar holds a particularly important DNS record called the nameserver.
- registrar — the service through which the domain is purchased.
- nameserver — the “mother” of DNS records, which contains the A record and MX records.
The nameserver contains the A record (website hosting) and the MX records (email hosting). So whatever service has the nameservers will control both of these things, as well as any other DNS record for that domain. However, individual DNS records can be pointed to other locations. Pointing MX records to a third party would put that third party in control of your email; pointing A records would put that third party in control of your website hosting.
- pointing — directing a DNS record to a different server, usually to make a 3rd party the host.
- A record — the DNS record that controls hosting. It points to a server’s IP address.
- MX record — the DNS record that controls email hosting. It points to a (mail) server.
For more on DNS records and hosting, see the Domains & DNS Overview.
Nameservers themselves can be pointed to a hosting service other than your registrar, such as BigCommerce. When this happens, that third party becomes not only your web host (because of the A record) but also the email host (because of the MX records). But you can still point individual DNS records to other locations, including back to the original host. A common scenario is to point the nameservers to BigCommerce, then point MX records in BigCommerce back to the registrar or to another email hosting service.
MX (mail exchange) records control email hosting by pointing to the mail server(s) responsible for accepting and sending email messages. The anatomy of an MX record is:
- Type: MX — email is what's being controlled in this record
- Host: your domain — the current host of what's being handled
- Value: the third-party mail server — the new host of what's being handled
- mail server — the server responsible for handling email messages sent to and from the recipient's domain
It is common for an email hosting service to have multiple mail servers in case one goes down. This requires pointing multiple MX records. When there are multiple MX records, you have to set a priority to determine the order in which the mail servers are checked. The mail servers are then checked in that order.
- priority — a number assigned to an MX record that determines the order in which it is checked for availability. The lowest number has the highest priority.
For example, you might have the following three MX records:
In this example, if you are sending mail to domain.com, your email service would first check to see if mail server 1 is up and available. If not, it would try mail server 2. If mail server 2 was also down, it would try mail server 3.
When an email is sent, it goes to whichever mail server the MX records point to. This mail server stores the email, and will continue to store any emails that were sent to it even if the MX records are pointed somewhere else later. Think of it as a piggy-bank; even if you stop putting anything in there, it still keeps what you added before.
Incoming Mail Servers
Left to its own devices, the mail server will only store the mail. It won’t send mail or allow anyone to access the mail. To access it, you would use an incoming mail server, which delivers the received mail to an email client or webmail service, which is what you use to actually read the email. Some compare the incoming mail server to a postal worker because it delivers the mail to your digital doorstep. In fact, the most popular protocol used by incoming mail servers is POP, which stands for Post Office Protocol.
- incoming mail server — the program that delivers mail from the mail server to an email client
- email client — a computer program for email, e.g. Outlook, Apple Mail, or Windows Live Mail
- webmail service — an online website for email, e.g. Gmail, Yahoo, or Hotmail
- protocol — the program that delivers mail from the mail server to an email client
POP is the protocol originally used for email. Created in 1986, the current version is referred to as POP3. POP simply downloads copies of the emails to read, and deletes the originals from the server. As a result, the email message is “tied” to the device that accesses the email. However, the email client can be easily reconfigured not to delete the original email from the server, which gives POP an important advantage: If you have multiple email clients set up and one of them accidentally deletes an important email, the others will still have access to it. When your incoming mail server uses POP, it is also called a POP server.
IMAP (Internet Message Access Protocol) is the other popular protocol for incoming servers. It syncs email clients with the mail server continuously, so that multiple devices all access the same data. For example, if you access your device from your mobile phone and your computer, both will receive new messages, and deleting a message on one will delete it on the other. The catch is that it will also delete the message from the server, so you have to be careful. When your incoming mail server uses IMAP, it is called an IMAP server.
- POP server — a program for retrieving mail. Used for syncing to the mail server at intervals.
- IMAP server — a program for retrieving mail. Used for syncing to the mail server continuously.
Outgoing Mail Servers
The mail server also needs an outgoing mail server to send mail. Outgoing mail servers use a protocol called SMTP (Simple Mail Transfer Protocol), which as we will see, is used for more than just sending mail. For this reason, outgoing mail servers are also called SMTP servers. When you send an email from your email client, the following process occurs:
- Your email client (or webmail) connects with the SMTP server.
- The email client provides the following information to the SMTP server:
- your email address
- your recipient's address
- the message itself
- The SMTP server looks at the domain of the recipient’s email address, and looks up the associated MX records to determine which mail server to deliver to (in order of priority).
- The SMTP server routes the message along a series of unrelated SMTP until it arrives at the recipient’s SMTP server.
- The recipient’s SMTP server scans the email to see if it recognizes the domain and username. It also makes sure the server that sent the message has the authority to send it (more details here). If everything checks out, it sends the message to the incoming mail server; otherwise, the sender gets a bounceback email.
- outgoing mail server — the program that transfers mail from the email client to the recipient’s mail server. Also called the SMTP server.
When connecting your email client, you will be asked to specify ports for the incoming and outgoing mail servers. The ports are locations inside the mail server where different programs run (think of it as units in an apartment building). For example, mail always arrives through Port 25 (SMTP) and is moved into storage. If you are using BigCommerce, the POP server in Port 995, or the IMAP server in 993, fetches the mail. When setting up email, you have to specify which ports the email client should be interacting with to send and receive messages.
- port — the unit inside the mail server where a specific program runs.