When you send an email, Gmail, Yahoo, or whatever your email server is will automatically know which email service to deliver your email to. It knows this via MX records. Your domain’s MX record consists of a list of mail servers that tell email services like Gmail where to deliver your incoming mail to. That’s pretty much it. It’s just like being listed in a virtual directory book, where your email address is your name, your MX record is your phone number, and the Internet itself is the book.
MX record (Mail Exchanger record) is a type of DNS record that tells email services where your email is hosted, allowing you to receive emails. MX record refers to certain types of resource records (RRs) in the Domain Name System (DNS) and it is used to gather domain information from a received email. In other words, when an email is received, the sending mail transfer agent requests the DNS for MX records. This produces a list of host names concerning the domain name of incoming mail, as well as its set preferences. Each record involves a type identification (A, MX, NS, etc.), DNS class (Internet, CHAOS, etc.), as well as a name field and a number.