In this design, we are going to talk about incoming mail server failover or MX failover. Our intention is to protect email loss during receiving. we need two mail servers for the design. from the DNS we will designate one as the primary or master server and the second one as the secondary or backup MX. if the primary server goes down, the secondary server will receive all emails.
When a sending server sends an email to a receiving server, it selects the domain’s primary MX server. normally email delivery will fail if the primary server is unreachable. But if there is a backup MX, the email will be received by the backup MX server. The adoption of Backup MX will eliminate the single point of failure scenario for inbound emails.
One thing to note, backup MX will not hold any mailboxes so it cannot deliver mail to inboxes, rather it will store mail to its queue and wait for the primary mail server to come alive, when available, it will deliver all emails to the primary one for the inbox delivery.
Here on the diagram, we declared two servers at the DNS as the primary MX and Backup MX.
How this Design Actually Works:
In this design, our primary MX server is performing full email operation for the organization, it is not only an MX server but also our outgoing server, email storage, POP/IMAP, and webmail server. So the organization’s total email operations are performed by the primary one. If the primary MX server goes down, the Backup MX server will receive all emails. But it will not provide any other services.
Normally email delivery is of two type’s local delivery and remote delivery, primary MX server will receive mail for local delivery because it has all the users’ information and inboxes to deliver. The Backup MX server, on the other hand, will receive mail only on crisis time, it will receive mail and stores in the queue for remote delivery. because backup MX doesn’t contain any user or inboxes where it can deliver. it will wait for the primary MX server to come alive and then deliver all the queued emails to the primary one.
1. here, we have two servers named “mailx1.mailserverguru.com” and “mailx2.mailserverguru.com” both must have public IP and be connected to the internet.
2. both systems must be able to receive mail from the internet, that’s why we have to setup an MX record at our DNS server. we have to assign MX with different Priority values, though, we can set the same priority to both servers but that is for load balancing scenario, I will describe that in the latter article, here in this design, MX priority is the main issue, let’s say
mailx1.mailserverguru.com Priority 10
mailx2.mailserverguru.com Priority 20
This Priority value means, whenever the sender’s mail server asks for our domains mail server address, our DNS server will respond with the above 2 server names, and with the priority value, it will deliver the mail to the lowest priority server, this is the rule for the mail servers, if the primary server is down, then the sender will deliver mail to the higher priority mail server.
You can watch this playlist for detail setup of Linux DNS Server.
Or, You can watch this video to see How to Setup MX record at Godaddy DNS
Let’s See Another Primary and Backup MX Scenario:
This design is more practical than the previous one because, most organizations do not provide two dedicated servers for mail server deployment. In this design, our backup MX server is at an ISP environment, most ISP companies or hosting providers provide email services or we can rent a dedicated VPS from them to store our emails for this temporary period.
Mail Storage at Backup MX Server:
Regarding storing mail at the backup server, we have two option’s, either we can configure Backup MX to store email at its queue, or we can store emails to its storage directly, if we want to store email on Backup MX storage, we have to configure the server with a configuration called “Domain Catchall Address”, which will receive all email and store on a single common email address for the whole domain, all recipients mail will be saved on this single mailbox at the backup MX server, in this case, the backup MX server will not try to deliver mail to primary one when alive, it will be primary servers responsibility to pull all email from that remote mailbox and deliver to the local users inbox. On Linux Environment this type of setup is done with two known email program named “fetchmail and procmail”, I will try to show you later this configuration.
If you want to learn more about Fetchmail and Procmail Please watch this video.