MX (Mail Exchange) is a type of DNS record that tells which mail servers accept email for a domain. It is the MX record that lets a sending server know where to deliver mail addressed to something like user@example.com.
Each MX record holds a numeric priority and a mail server name, for example "10 mail.example.com". The lower the number, the higher the priority: a sending server first tries the record with the smallest value and only falls back to the others if the primary server is unreachable. The name from the MX is then resolved through an A record into a concrete IP address where the SMTP connection is established.
A few details are worth keeping in mind when working with MX:
A single MX record is not enough for reliable email: alongside it, SPF, DKIM and DMARC are configured in TXT records to confirm the sender's authenticity and reduce the chance of messages landing in spam.