16 November 2026 · DMARC Engine · 10 min read
- Use specific include statements or IP addresses in SPF records
- Avoid using wildcards in SPF records
- Verify third-party SPF records before including them
- Use permissive SPF records to allow legitimate mail from multiple sources
Envelope Sender Alignment Failures
Envelope sender alignment failures occur when the domain in the MAIL FROM command does not align with the domain in the From header. This can happen when a domain uses a third-party mail service, such as a marketing platform or a hosted email provider. A common pattern is for the envelope sender to be set to a subdomain of the mail service provider, rather than the domain of the sender.
For example, if a domain example.com uses a marketing platform hosted on mail.marketing-platform.com, the envelope sender might be set to bounce@mail.marketing-platform.com. If the SPF record for example.com does not include the IP addresses of the marketing platform, the email may fail SPF checks.
example.com. IN TXT "v=spf1 include:mail.marketing-platform.com -all"This can be mitigated by including the IP addresses of the marketing platform in the SPF record for example.com, or by using a dedicated subdomain for the marketing emails.
Warning:
Using a wildcard in an SPF record, such as include:*._spf.example.net, can lead to alignment failures if the subdomain does not match the domain in the From header. It is generally safer to explicitly list the subdomains or IP addresses in the SPF record.
A hosted or managed setup may handle envelope sender alignment failures differently, depending on the configuration and settings. It is essential to review the documentation and settings for the specific mail service or provider to ensure proper alignment and SPF validation.
Understanding SPF Alignment
SPF alignment is crucial for ensuring that the envelope sender domain aligns with the domain in the From header of an email. A common pattern is for organisations to use a third-party mail service, which can lead to SPF alignment issues if not properly configured. The SPF record for a domain, such as example.com, is typically published as a TXT record, for example:
"v=spf1 include:_spf.example.net -all"This record includes the _spf.example.net record, which may contain additional include statements or IP addresses. Receivers typically check the envelope sender domain against the SPF record of the domain in the From header, and a mismatch can lead to SPF alignment failures.
When using a hosted or managed setup, the provider may handle SPF alignment differently. For instance, some providers may automatically set up an SPF record for the hosted domain, while others may require manual configuration. A list of common SPF record configurations includes:
* Include statements for third-party mail services
* IP addresses for in-house mail servers
* Modifier statements, such as redirect or exp
# Example of an SPF record with include statements and IP addresses
spf_record = "v=spf1 include:_spf.example.net ip4:192.0.2.1 -all"
Warning: Using a wildcard in an SPF record, such as include:*.example.net, can lead to unintended consequences, as it may include records that are not intended for use with the domain. It is generally recommended to use specific include statements or IP addresses to avoid alignment issues. In a real-world scenario, an organisation may have multiple third-party mail services, each requiring a separate include statement in the SPF record. The aggregate reports will show SPF alignment failures if the envelope sender domain does not match the domain in the From header, highlighting the need for careful configuration of SPF records.
Operational Guidance for Third-Party Mail Services
When using third-party mail services, envelope sender alignment pitfalls can be particularly problematic, as these services often have their own SPF records and requirements. A common pattern is for these services to recommend including their SPF record in the domain owner's SPF record, using the include mechanism. For example, a third-party mail service might provide an SPF record like this:
v=spf1 include:third-party-service.com -allHowever, this approach can lead to issues if the third-party service's SPF record is not properly configured or if it includes other domains that are not authorised to send mail on behalf of the domain owner.
To avoid these issues, it is generally recommended to use the a or ip4/ip6 mechanisms to specify the IP addresses of the third-party mail service, rather than including their SPF record. This approach provides more control over which IP addresses are authorised to send mail and can help to prevent alignment issues. For example:
v=spf1 a:third-party-service.com ip4:192.0.2.1 -allThis approach also allows the domain owner to maintain control over their SPF record and avoid any potential issues that may arise from including a third-party SPF record.
In a hosted or managed setup, the provider may handle SPF configuration on behalf of the domain owner. However, it is still important for the domain owner to understand how their SPF record is configured and to ensure that it is properly aligned with their envelope sender domain.
v=spf1 include:_spf.example-hosting.com -allIn this case, the domain owner should ensure that the hosting provider's SPF record is properly configured and aligned with their envelope sender domain.
Warning: including a third-party SPF record without proper verification can lead to security issues, such as allowing unauthorised senders to send mail on behalf of the domain owner. It is essential to carefully review and verify any third-party SPF records before including them in the domain owner's SPF record.
When configuring SPF for third-party mail services, it is also important to consider the potential impact on email deliverability. A strict SPF record that only includes the IP addresses of the third-party mail service may block legitimate mail from other sources, such as mailing lists or email clients. To mitigate this risk, it is recommended to use a more permissive SPF record that includes a wider range of IP addresses, while still maintaining proper alignment with the envelope sender domain. For example:
v=spf1 a:third-party-service.com ip4:192.0.2.1/24 -allThis approach allows for a wider range of IP addresses to be authorised, while still maintaining control over which IP addresses are allowed to send mail on behalf of the domain owner.
Real-World SPF Record Examples
A common pattern is for organisations to publish SPF records that include multiple IP addresses, as well as references to third-party mail services. For example, a company may use a hosted email service, and also send email from their own servers, and from a marketing automation platform.
v=spf1 ip4:192.0.2.1 include:_spf.examplehostedemail.com include:_spf.examplemarketingautomation.com -allThis record specifies that email can be sent from the IP address 192.0.2.1, as well as from the services hosted by examplehostedemail.com and examplemarketingautomation.com. The -all mechanism at the end indicates that any email not matching these rules should be rejected.
In a managed setup, the hosted or managed service may handle the SPF record on behalf of the organisation, and may use a variety of mechanisms to authenticate email, such as IP addresses, or domain names. For instance, a managed service may publish a record like this:
v=spf1 include:managedservice.example.com -allThis record delegates the responsibility for specifying the allowed senders to the managed service, which may then publish its own record listing the IP addresses or domain names of its mail servers.
When setting up SPF records, it is crucial to ensure that all mail servers that send email on behalf of the organisation are included in the record, to avoid envelope sender alignment failures. A list of common mail services and their recommended SPF record configurations includes:
* Google Workspace: include:_spf.google.com
* Microsoft 365: include:spf.protection.outlook.com
* Mailchimp: include:mailchimp.net
import dns.resolver
def get_spf_record(domain):
answers = dns.resolver.resolve(domain, 'TXT')
for answer in answers:
if answer.to_text().startswith('v=spf1'):
return answer.to_text()
return None
Tip: When troubleshooting SPF alignment issues, it can be helpful to use online tools or scripts to check the SPF records for a given domain, and to verify that the records are correctly formatted and include all the necessary mail servers.
Aggregate Report Analysis for SPF Alignment Issues
When analysing aggregate reports for SPF alignment issues, a common pattern is to look for messages that fail SPF alignment due to a mismatch between the envelope sender domain and the SPF record. The aggregate reports will show the domain that attempted to send the message, the IP address of the sending server, and the result of the SPF check.
_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:aggrep@example.com"This information can be used to identify which senders are causing the alignment issues and to update the SPF record accordingly. For example, if the aggregate report shows that messages from a third-party mail service are failing SPF alignment, the SPF record can be updated to include the IP addresses of that service.
example.com. IN TXT "v=spf1 include:third-party-mail-service.com -all"Receivers typically use the domain in the MAIL FROM command to perform the SPF check, so it is essential to ensure that the envelope sender domain matches the domain in the SPF record. In a hosted or managed setup, the provider may handle the SPF record configuration, but it is still crucial to understand how the envelope sender alignment works and how to troubleshoot issues.
subdomain.example.com. IN TXT "v=spf1 redirect=example.com"A list of common issues that can cause SPF alignment failures includes:
* Mismatch between the envelope sender domain and the SPF record
* Missing or incorrect SPF record
* IP addresses not included in the SPF record
* Use of a third-party mail service without updating the SPF record
import dns.resolver
answers = dns.resolver.resolve('example.com', 'TXT')
for rdata in answers:
for txt_string in rdata.strings:
print(txt_string)Warning: when updating the SPF record to include new IP addresses or domains, it is essential to test the changes thoroughly to avoid accidentally blocking legitimate email traffic.
In some cases, the aggregate reports may show that messages are failing SPF alignment due to a missing or incorrect SPF record. In this case, the solution is to update the SPF record to include the correct IP addresses or domains. By carefully analysing the aggregate reports and updating the SPF record accordingly, it is possible to improve the deliverability of emails and reduce the risk of SPF alignment issues.
Common Pitfalls and Troubleshooting
A common pattern is for senders to overlook the implications of using a third-party mail service, where the envelope sender domain may not match the visible 'from' domain.
Receivers typically check the envelope sender against the SPF record published for that domain, so a mismatch can cause alignment failures.
v=spf1 include:_spf.example.net -all
In a hosted setup, the provider may handle this by using a custom domain for the envelope sender, such as mail123.example.net, which the sender must then include in their SPF record.
- using a dedicated subdomain for mail services to simplify SPF management
- ensuring all third-party services are included in the SPF record
- monitoring aggregate reports for signs of alignment issues
import re
# simple example of parsing an aggregate report for alignment failures
def parse_report(report):
failures = re.findall(r'alignement\_failures=(\d+)', report)
return failures
Tip: regularly review and update SPF records to reflect changes in mail services or infrastructure, as stale records can lead to delivery issues.
Best Practices for Maintaining SPF Alignment
To maintain SPF alignment, it is crucial to ensure the envelope sender domain matches the header from domain. A common pattern is to use a subdomain for the envelope sender, such as mail.example.com, to avoid alignment issues with the header from domain example.com.
example.com. IN TXT "v=spf1 a mx ip4:192.0.2.1 include:_spf.example.com -all"
This approach allows for easier management of SPF records, especially in hosted or managed setups where the mail server IP addresses may change.
Tip:
> When using a third-party mail service, it is essential to include their SPF record in your domain's SPF record to avoid alignment issues, using the include mechanism as shown in the example above.
In general, receivers typically check the envelope sender domain against the SPF record published on that domain, so it is vital to publish the SPF record on the correct domain.