The short answer is the mx mechanism. In a Sender Policy Framework (SPF) record, you can use several different types of mechanisms to specify which servers are authorized to send email on behalf of your domain. The mx mechanism is specifically designed to approve any sending server that is also listed as a mail exchanger (MX) in your domain's DNS records.
As SiteGround explains, when you add the mx mechanism to your SPF record, all the servers defined in your domain's MX records are automatically added to the approved senders list. This is particularly useful if the same servers handle both your incoming and outgoing email.
When a recipient's mail server receives an email, it checks the SPF record of the sender's domain to verify the email's authenticity. If this SPF record contains the mx mechanism, the server performs a series of DNS lookups. First, it queries the MX records for the domain in the SPF record. Then, for each MX record found, it looks up its corresponding IP address (or addresses). If the IP address of the server that sent the email matches one of these IP addresses, the SPF check passes for this mechanism.
The syntax for the mx mechanism is quite straightforward. It can be used in two primary ways in your SPF record:
The mx mechanism is ideal for simpler email setups where the same servers are responsible for sending and receiving mail. It avoids having to list IP addresses explicitly, which can be helpful if those IPs change.
However, it's important to be aware of the SPF 10 DNS lookup limit. Each mx mechanism consumes at least one DNS lookup to find the MX records, and then additional lookups for the IP addresses associated with them. As noted in a discussion on the GCA Community, this can quickly add to your total lookup count. If your SPF record is already complex with multiple include statements, adding an mx mechanism could push you over the limit, causing validation issues.
For this reason, if you use a third-party email provider like Google Workspace or Microsoft 365, it is almost always better to use their recommended include mechanism (e.g., include:spf.protection.outlook.com) rather than the mx mechanism. The include is managed by the provider and is optimized for deliverability and the lookup limit.