AegisAI Lab · Lab Note 003

How to Add a Third-Party Email Security Layer to Google Workspace

Two ways in: connect through Google's APIs and leave mail flow alone, or put a gateway in front of Gmail and change your MX records. Here are the exact Admin console steps for both.

How to add a third-party email security layer to Google Workspace: API connection or inbound gateway.

You can add a third-party email security layer to Google Workspace in one of two ways. An API-based integration connects to Gmail through Google's APIs, inspects mail inside the mailbox and changes nothing about how mail is delivered. A secure email gateway sits in front of Gmail: you point your MX records at the gateway and configure Gmail's inbound gateway setting to accept mail from it. Choose the model first, because it decides which Admin console settings, DNS records and tests the rest of the project needs.

$3.05B
reported business email compromise losses in 2025, across 24,768 complaints
0
MX record changes needed for an API-based integration
24h
for Gmail inbound gateway changes to take full effect, per Google

Sources: FBI IC3 2025 Internet Crime Report; Google Workspace Admin Help, Set up an inbound mail gateway.

Key takeaways

  • There are two deployment models: an API-based integration (no mail-flow change) and a secure email gateway (MX records point to the gateway first).
  • API integrations are authorized by a super administrator, through domain-wide delegation or a Marketplace app, with the narrowest OAuth scopes the vendor needs.
  • Gateways are configured in Gmail's Inbound gateway setting. Turn on "Reject all mail not from gateway IPs" or attackers can deliver straight to Google's MX servers and skip the gateway.
  • With a gateway, Gmail does not enforce the sender's DMARC policy for mail that arrives through it, so the gateway must handle that job.
  • Run the new layer in monitor mode on a pilot group, check headers and authentication results, then roll out.

How to add a third-party email security layer to Google Workspace in three steps

Adding a third-party email security layer to Google Workspace comes down to three decisions: the deployment model, the access you grant it, and how you prove it works before it touches every mailbox.

  1. Choose API-based or gateway

    An API layer reads and acts on mail that Gmail has already accepted. A gateway inspects mail before Gmail sees it. The comparison table below sets out the trade-offs.

  2. Grant access in the Google Admin console

    For an API layer, a super administrator authorizes the vendor's client ID and OAuth scopes. For a gateway, someone with the Gmail Settings administrator privilege adds the gateway's IPs to Inbound gateway, and your DNS owner updates the MX records.

  3. Pilot, verify, then enforce

    Start with a small group in monitor mode, compare the layer's verdicts with what users actually received, check SPF, DKIM and DMARC results in the headers, and only then switch on automatic remediation for everyone.

Both models assume Google Workspace's own protections stay on. For the wider picture of how platform security and an added layer divide the work, see our guide to email security for Microsoft 365 and Google Workspace.

API-based vs. gateway: choosing your third-party email security layer for Google Workspace

An API-based layer is the lower-risk change because mail delivery never depends on it. A gateway gives you a pre-delivery block point, at the cost of DNS work and a new dependency in the mail path.

QuestionAPI-based integrationSecure email gateway (MX change)
Where it sitsConnected to Gmail through Google's APIs, alongside the mailboxIn front of Gmail, in the delivery path
MX record changeNoneRequired
MX records point to the gateway
Admin console workAuthorize client ID and OAuth scopes (super administrator)Inbound gateway IPs, TLS, spam header rules (Gmail Settings administrator)
When it inspects mailAfter Gmail accepts it; can remove messages already in inboxesBefore Gmail accepts it; can block or quarantine before delivery
Internal mail between your own usersVisible, because it reads the mailboxUsually not seen, because it never crosses the gateway
If the vendor has an outageMail still flows; inspection pausesInbound mail can queue or bounce
Authentication impactNone on SPF, DKIM or DMARCGmail stops enforcing sender DMARC for gateway mail; SPF and DKIM need care

Many teams start with an API layer because it can be piloted without touching DNS. If you are moving away from an existing gateway, our secure email gateway migration guide covers the cut-over.

How to connect an API-based third-party email security layer to Google Workspace

An API-based layer is connected by a super administrator, who grants the vendor's app access to Gmail data in the Google Admin console. Google's domain-wide delegation guide sets out the steps. Follow your vendor's instructions where they differ.

  1. Get the client ID and scope list from the vendor

    Ask for the OAuth client ID and the exact OAuth scopes the integration needs. Google advises that the scopes be "appropriately narrow". Question any scope that is broader than reading and moving mail.

  2. Sign in as a super administrator

    Only a super administrator can manage domain-wide delegation. If multi-party approval is on for your organization, a second super administrator must approve the change.

  3. Open domain-wide delegation

    Go to Menu › Security › Access and data control › API controls, then click Manage Domain Wide Delegation.

  4. Add the client and its scopes

    Click Add new, paste the client ID, add each OAuth scope, then click Authorize. An error usually means the client ID is not registered with Google or a scope is duplicated or unsupported.

  5. Finish the connection in the vendor's console

    Complete the vendor's Google Workspace setup, choose a pilot group, and confirm it can see new messages arriving in those mailboxes.

Some vendors install as a Google Workspace Marketplace app instead. The flow is shorter, but review the same thing: which scopes are requested, and whether they match what the product actually does.

How to configure a secure email gateway for Google Workspace with MX record changes

A gateway deployment has two halves: DNS, so that mail reaches the gateway first, and Gmail's Inbound gateway setting, so that Gmail trusts the gateway and reads its verdicts. Google's inbound mail gateway guide is the reference.

Update your MX records

  1. Lower the TTL on your MX records a day ahead, so a rollback takes effect quickly.
  2. Replace Google's MX records with the gateway's MX hostnames and priorities, and remove any MX record that still points straight to Google.
  3. Wait for the old TTL to expire, then send a test message to a user in your domain and confirm the gateway processed it.

Configure the Inbound gateway in the Google Admin console

  1. Open the setting

    Go to Menu › Apps › Google Workspace › Gmail › Spam, Phishing and Malware, select your top-level organization, scroll to Inbound gateway and click Edit. You need the Gmail Settings administrator privilege.

  2. Add every gateway IP

    Add each public IP address or range the gateway sends from. Gmail does not accept private IP addresses here. If mail passes through more than one gateway, add them all.

  3. Turn on the protective options

    Select Automatically detect external IP so SPF and spam checks use the original sender's IP, Reject all mail not from gateway IPs to close the bypass path, and Require TLS for connections.

  4. Map the gateway's spam verdicts

    If the gateway tags suspicious mail with a header, enter that header as a regular expression under "Message is considered spam if the following header regexp matches", so Gmail acts on the gateway's verdict.

  5. Save and wait

    Google says changes can take up to 24 hours, though they usually apply sooner. Track them in the Admin console audit log.

Test the lockdown: from an outside system, send a message straight to Google's MX servers for your domain. It should be rejected. A gateway that can be skipped this way protects only the mail that happens to route through it, which is why attackers look for these gaps. Our threat research shows how attackers bypass a secure email gateway.

Adding the gateway's IP to an allowlist does not change how Gmail delivers or filters mail. Configure the Inbound gateway setting instead.

Paraphrased from Google Workspace Admin Help

Outbound gateway (optional)

To inspect outgoing mail as well, add an outbound gateway at Apps › Google Workspace › Gmail › Routing › Outbound gateway. This applies to the top-level organization only; use a routing rule if you need it for part of the organization. Google's outbound gateway guide says the gateway should accept mail only from Google Workspace IPs, so it does not become an open relay.

SPF, DKIM and DMARC for a third-party email security layer in Google Workspace

An API-based layer needs no authentication changes. A gateway does, because it changes the path mail travels and the IPs that send it. Our explainer on SPF, DKIM and DMARC architecture covers the background.

  1. SPF. If you route outbound mail through the gateway, Google says your SPF record must include both Google Workspace and the outbound gateway, or that mail is more likely to be marked as spam. Stay within the 10 DNS lookup limit set by RFC 7208; going over it makes SPF fail.
  2. DKIM. Turn on DKIM signing at Apps › Google Workspace › Gmail › Authenticate email, following Google's DKIM setup guide. If an outbound gateway modifies messages, they will likely fail DKIM, so set it to leave messages unchanged where possible.
  3. DMARC. SPF or DKIM must be working before DMARC, and Google advises waiting 48 hours after setting them up. Start at p=none, read the reports, fix alignment for every sending service, then move to quarantine and reject.
  4. Inbound DMARC with a gateway. Gmail does not enforce the sender's DMARC policy for mail arriving through an inbound gateway, although it still records the authentication results. Make sure the gateway enforces DMARC on inbound mail.

Pilot checklist before you roll out to every Google Workspace user

Pilot the new layer on a small group first. Then you can measure what it catches, and what it gets wrong, before it acts on everyone's mail.

  • Pick a pilot group that includes people attackers target: finance, executives and their assistants.
  • Run in monitor or report-only mode first, with no automatic removal.
  • Send test messages from outside and check the headers for SPF, DKIM and DMARC results and the layer's verdict.
  • For a gateway, confirm that a direct-to-MX test message is rejected and that TLS is in use.
  • Compare the layer's findings with messages users reported, then turn on remediation group by group.

Business email compromise is why this testing matters. It caused $3,046,598,558 in reported losses across 24,768 complaints in 2025, and a typical BEC message has no attachment or link to scan. For a scorecard to use during the pilot, see how to evaluate email security vendors.

Where AegisAI fits in Google Workspace

AegisAI uses the API model. It connects to Google Workspace (or Microsoft 365) through the API, with no MX change and no rerouting of mail. Google's own protections stay in place, and AegisAI investigates the messages that get through them. To learn more about the approach, read cloud email security for Google Workspace, or book a demo to see it on your own mail.

FAQ

How do I add a third-party email security layer to Google Workspace?

Choose a deployment model, then grant access in the Google Admin console. For an API-based layer, a super administrator authorizes the vendor's client ID and OAuth scopes under Security, API controls, Domain-wide delegation. For a gateway, point your MX records at the gateway and add its IPs under Gmail, Spam, Phishing and Malware, Inbound gateway. Pilot on a small group before full rollout.

Do I need to change MX records to add a third-party email security layer to Google Workspace?

Only for a gateway. An API-based integration connects through Google's APIs and leaves your MX records and mail flow unchanged. A secure email gateway needs your MX records to point to the gateway so it receives mail before Gmail does.

Should I choose an API-based integration or a secure email gateway for Google Workspace?

An API-based integration is quicker to pilot, sees internal mail and keeps mail flowing if the vendor has an outage. A gateway can block messages before they are delivered, but it adds DNS changes, a dependency in the mail path and extra SPF, DKIM and DMARC work. Many teams start with an API layer.

What permissions does a third-party email security layer need in Google Workspace?

An API-based layer needs a super administrator to authorize its OAuth client ID and scopes through domain-wide delegation or a Marketplace app install. Google advises keeping the scopes appropriately narrow. A gateway needs the Gmail Settings administrator privilege to configure the Inbound gateway setting.

How do I stop attackers from bypassing my email gateway and delivering straight to Gmail?

In the Inbound gateway setting, add every gateway IP and select "Reject all mail not from gateway IPs". Then test by sending a message from an outside system directly to Google's MX servers for your domain. It should be rejected.

Does Gmail still enforce DMARC when mail comes through a third-party gateway?

No. Google states that Gmail does not enforce the sender's DMARC policy for mail that arrives through an inbound gateway, although it still uses the authentication results. Your gateway should enforce DMARC for inbound mail.

How do I test a third-party email security layer before rolling it out to all users?

Run it in monitor mode on a pilot group that includes finance and executives. Check the message headers for SPF, DKIM and DMARC results and the layer's verdict, compare its findings with messages users reported, and for a gateway confirm that direct-to-MX delivery is rejected. Then turn on remediation group by group.

How does AegisAI connect to Google Workspace?

AegisAI uses the API model. It connects to Google Workspace through Google's APIs, with no MX record change and no rerouting of mail. Google's own protections stay in place, and AegisAI investigates the messages that get through them.

Recent posts

Every email, investigated.