schedule 10-min read

How Secure Email Gateways Affect DMARC, SPF and DKIM

DMARC AI editorial team · Last updated

A secure email gateway changes the sending IP and can alter messages, which affects SPF, DKIM and DMARC in both directions. What to configure and check.

01

Introduction

A secure email gateway (SEG) affects DMARC, SPF and DKIM because it relays mail and often changes it. Outbound, the gateway becomes the sending IP that SPF checks and should be the last system to DKIM-sign. Inbound, a gateway in front of Microsoft 365 or Google Workspace hides the original sender's IP and can break signatures before the mailbox platform evaluates DMARC.

Gateways are filtering services that sit between the internet and the mailbox platform, either cloud services or appliances. For an MSP, getting the gateway right is often what separates a smooth DMARC rollout from weeks of false failures. This guide covers both directions, the configuration that keeps authentication aligned, and how to read gateway effects in aggregate reports. For the protocol background, see the DMARC guide.

02

Key takeaways

  • Outbound, the gateway's IPs must be authorised in SPF, and the gateway should DKIM-sign with the client's domain as the last step before mail leaves.
  • Any change after signing, such as a disclaimer or subject tag, breaks DKIM. Add it before signing, or let the gateway sign after it.
  • Inbound, a gateway in front of Microsoft 365 makes Microsoft see the gateway's IP. Enhanced Filtering for Connectors or a trusted ARC sealer restores the original authentication.
  • DMARC passes with one aligned result, so an aligned DKIM signature from the gateway protects mail even where SPF alignment is hard.
  • Aggregate reports show the gateway's IPs as the source for outbound mail, which is the quickest way to confirm the setup works.
03

How does a secure email gateway change the mail flow?

A gateway changes the mail flow by adding a hop. Inbound, the MX record points at the gateway, which filters mail and passes it to the mailbox platform. Outbound, the mailbox platform uses a connector or smart host to send through the gateway, which then delivers to the internet.

Each hop matters for authentication:

Direction What the receiver sees Authentication effect
Outbound The gateway's IP and whatever the gateway did to the message SPF checks the gateway's IP; DKIM must survive or be added by the gateway
Inbound Your mailbox platform sees the gateway's IP, not the original sender's SPF for the original sender fails; DKIM can break if the gateway modified the message
04

How does a gateway affect outbound SPF?

Outbound, SPF is checked against the IP that connects to the receiver, which is now the gateway. If the client's SPF record does not authorise the gateway's IPs, SPF fails for every message that leaves through it.

Most cloud gateways publish an SPF include for their sending ranges, and the vendor's setup guide names it. Add it to the client's SPF record, then check the lookup count: RFC 7208 allows at most 10 DNS-querying mechanisms, and gateway includes can be expensive. SPF too many DNS lookups covers the fix if you go over.

v=spf1 include:spf.protection.outlook.com include:_spf.gateway.example -all

The second include above stands for the gateway vendor's published include. Whether SPF also aligns depends on the envelope sender (Return-Path) domain the gateway uses. If it keeps the client's domain, SPF aligns; if it rewrites the envelope to its own domain, SPF passes for the gateway but does not align, and DMARC then depends on DKIM. Why does DMARC fail when SPF passes explains that difference.

05

Where should DKIM signing happen when a gateway relays outbound mail?

DKIM signing should happen at the last system that changes the message, which is usually the gateway. The NCSC's DKIM guidance says the signature should be the last addition before a message is released, and notes that a filtering service may apply it instead of your mail server.

There are two workable patterns:

  1. The mailbox platform signs, and the gateway does not modify the message. Microsoft 365 or Google Workspace signs with the client's domain, and the gateway passes the message through unchanged. This works only if the gateway adds no disclaimers, banners or subject tags.
  2. The gateway signs with the client's domain. The gateway adds its changes, then signs with a selector published in the client's DNS. This is the safer pattern when the gateway modifies outbound mail.

What does not work is the mailbox platform signing, the gateway changing the body or signed headers, and nothing re-signing. The original signature then fails, and if SPF is not aligned either, DMARC fails. A gateway that signs only with its own domain gives a valid signature that does not align with the client's From address. Use a custom DKIM key for the client's domain, generated in the gateway, with the public key published as the selector record the vendor specifies. DKIM selectors explained helps keep selectors apart.

06

Why do disclaimers and banners break DKIM?

Disclaimers and banners break DKIM because the signature covers a hash of the body and selected headers. RFC 6376, the DKIM standard, defines how that hash is calculated; changing the body after signing changes the hash, so verification fails at the receiver.

Common culprits on outbound mail:

  • legal disclaimers appended to the body;
  • "external" or classification banners;
  • subject tags such as [Encrypted];
  • link rewriting or attachment stripping by data loss prevention rules.

The fix is ordering: make every change before the final signature. Send a test message to a mailbox you control and read the Authentication-Results header. The email header guide shows where to look, or paste the header into the email header analyser.

07

How does an inbound gateway affect DMARC checks in Microsoft 365?

An inbound gateway in front of Microsoft 365 makes Microsoft see the gateway's IP as the source of every message. SPF for the original sender then fails, and if the gateway modified the message, DKIM fails too. Microsoft's own documentation says such messages arrive with the IP of the last hop in front of Microsoft 365.

Microsoft offers two fixes, and they solve different parts of the problem:

  • Enhanced Filtering for Connectors (skip listing) tells Microsoft 365 to skip the gateway's IPs and evaluate the real source IP. Microsoft Learn describes it as preserving the source IP and sender information. It applies when the MX record does not point to Microsoft 365.
  • Trusted ARC sealers tell Microsoft 365 to accept the authentication results a gateway recorded before it changed the message. You add the gateway's ARC signing domain in the Defender portal under Email Authentication Settings, ARC tab, or with Set-ArcConfig, as Microsoft documents.

ARC itself is defined in RFC 8617. It only helps when the gateway seals messages and the receiver trusts that sealer. The full Microsoft 365 scenario is in why DMARC fails with a gateway in front of Microsoft 365 and the setup steps in Enhanced Filtering for Connectors for MSPs. ARC explained covers the protocol.

08

Does a gateway enforce DMARC on inbound mail?

Most gateways can evaluate the sender's DMARC policy and quarantine or reject failing mail, but local policy can override it. Allow lists and "trusted sender" rules that skip authentication checks let mail through that the sending domain asked receivers to reject.

Two points matter for MSPs:

  • Decide where enforcement happens. If the gateway enforces DMARC and Microsoft 365 also evaluates it, make sure both see correct results, otherwise one layer quarantines mail the other considers clean.
  • Audit bypass rules. A broad bypass for a partner domain removes DMARC protection for exactly the domain attackers like to spoof.

Inbound enforcement concerns other organisations' domains. It does not change your client's own DMARC results at other receivers.

09

How do you see gateway effects in DMARC aggregate reports?

Aggregate reports from receivers list the source IP of each message, so outbound mail that leaves through a gateway shows the gateway's IPs. That is the quickest check that the setup works.

What to look for per client domain:

What the report shows Likely meaning Action
Gateway IPs, SPF pass, DKIM pass and aligned Gateway authorised and signing correctly None
Gateway IPs, SPF pass, DKIM fail A change after signing, or the gateway is not signing Check disclaimers and gateway DKIM settings
Gateway IPs, SPF fail Gateway include missing from SPF Add the vendor's include, then check the lookup count
Mailbox platform IPs alongside gateway IPs Some mail bypasses the gateway Check connectors and routing rules

Reports are defined in RFC 9990. In DMARC AI, aggregate reports for every client domain are grouped by sender, so gateway traffic appears as one named source, and the AI assistant can check the live SPF and DKIM records while you work through a failure.

10

What should an MSP check before enforcing DMARC on a domain with a gateway?

Check routing and authentication for both directions before moving past p=none:

  1. Map the mail flow. Record MX, outbound connectors and smart hosts for the client.
  2. Authorise the gateway in SPF and keep the lookup count under 10.
  3. Choose one signing point and publish its DKIM selector in the client's DNS.
  4. Move disclaimers and banners before signing, or let the gateway sign after them.
  5. Configure Enhanced Filtering or trusted ARC sealers for inbound mail through a gateway in front of Microsoft 365.
  6. Review allow lists and bypass rules that skip authentication.
  7. Confirm in aggregate reports that gateway traffic passes with aligned DKIM for at least two weeks.

Then move the policy from p=none to p=quarantine to p=reject, one step at a time when reports are clean. Moving from monitoring to enforcement safely covers the steps. Vendor-specific notes are in the Proofpoint and Mimecast guides, and clients still on Exchange Server should read DKIM for Exchange Server.

11

FAQ

Do I need to add my email gateway to SPF?

Yes, if outbound mail leaves through the gateway. Receivers check SPF against the connecting IP, which is the gateway's. Add the include or IP ranges the vendor publishes, keep the record under 10 DNS lookups, and confirm in aggregate reports that gateway traffic passes SPF.

Should the gateway or Microsoft 365 sign DKIM?

Whichever system makes the last change to the message. If the gateway adds disclaimers or banners, let the gateway sign with the client's domain. If the gateway passes mail through unchanged, Microsoft 365 can sign. Never let both sign while the gateway still modifies the body after Microsoft's signature.

Why does inbound mail fail SPF after we added a gateway?

Because Microsoft 365 now sees the gateway's IP instead of the original sender's, and that IP is not in the sender's SPF record. Enable Enhanced Filtering for Connectors so Microsoft evaluates the real source IP, and consider adding the gateway as a trusted ARC sealer.

Can a gateway make DMARC pass for mail it changes?

Only for its own outbound signing. For outbound mail, the gateway can re-sign with the client's domain, giving an aligned DKIM pass. For inbound mail it cannot change the sender's results, but an ARC seal can carry the original results to a receiver that trusts the gateway as a sealer.

Does a gateway affect my DMARC reports?

Yes. For outbound mail through the gateway, receivers report the gateway's IPs as the source, so the gateway appears as a sender in your aggregate reports. Seeing it pass with aligned DKIM there is the best evidence that the configuration is correct.

12

Final thoughts

Treat a secure email gateway as part of the authentication path. Outbound, it is a sender that must be in SPF and should sign last with the client's domain. Inbound, it is a hop that Microsoft 365 needs to see past. Configure both directions, then let the aggregate reports confirm it before you enforce.

Related articles

Related tools

Ready to Implement?

Get authenticated mail moving in minutes: start free, book a guided demo, or talk to the team about your stack.