MX records are a specific type of DNS record, stored on 1000s of DNS servers around the Internet, which form the mechanism for getting emails delivered to the right place.
When a mail-server has an email to deliver, for example to email@example.com, it asks its nearest DNS server for the name of the computer responsible for accepting email for addresses at companymail.com.
This name is contained in the MX record for the companymail.com domain and, once the sending mail-server knows what this is, it will connect to this mail-server and attempt to deliver the email.
There’s a bit more to the MX record system:-
You can have multiple MX records for an email domain, and each record can have a different priority.
The MX records for addresses @companymail.com might be:-
mail1.companymail.com – priority 5
mail2.companymail.com – priority 10
The lower the number, the higher the priority.
A sending mail-server will first try to send an email destined for a companymail.com address to the computer called mail1.companymail.com.
However, if this computer fails to respond within a certain time period, it will then try to send the email to the computer called mail2.companymail.com instead.
If neither respond it will wait a short period and then try the first one again.
This is a great automatic backup system that ensures that email will continue to be delivered if the main mail-server computer, in this case mail1.company.com, fails.