Email
Research
Email engineering guide

Connecting Gmail to a multi-tenant SaaS product

The OAuth redirect is only the front door; a production Gmail connection also needs tenant ownership, verified scopes, token isolation, baseline sync, and an understandable reconnect state.

Research surface only. This guide documents architecture and evaluation criteria; it does not describe a released DewEngine connector.
01
Application setup

Own the Google trust boundary

Configure a Google Cloud project, consent screen, exact redirect URI, and the smallest Gmail scopes required by the feature. Production use of sensitive or restricted scopes may require verification before broad customer access.

02
Hosted connection

Bind OAuth state to the correct SaaS user

Create a short-lived connection intent that names the workspace and user, validate OAuth state at the callback, exchange the code on the server, and return only a DewEngine account ID to the browser.

  • One-time state value
  • Server-side token exchange
  • Workspace and user ownership
  • No provider token in the frontend
03
Activation

Do not call the account active before sync is ready

Validate the mailbox identity, encrypt refresh material, run the chosen baseline synchronization, create the Gmail watch, and expose progress. A successful redirect alone does not prove background access will remain healthy.

04
Operations

Design reconnection as part of onboarding

Tokens can be revoked and watches expire. Before upstream revocation, identify every product account attached to the same Google user and API project: Google can invalidate the combined scopes and tokens across every client in that project. Surface that grant-wide blast radius and never silently fall back to stored credentials.

  • Grant-scoped health
  • Watch renewal schedule
  • Grant-wide revocation and resync audit trail
Questions

Before you build.

Can one Google OAuth connection be shared by several SaaS tenants?+

Do not copy one credential into several tenant rows. Google can combine a user's scopes across clients in one API project, so DewEngine needs one grant owner, tenant-fenced product attachments, and an explicit whole-grant revocation boundary. Independent tenant revocation requires separate approved Cloud projects.

Where should Gmail refresh tokens live?+

In an encrypted server-side token store with strict tenant and service access controls, never in browser storage or ordinary application records.

Can I use DewEngine's email connectors today?+

Not yet. Gmail, Microsoft Graph, and IMAP/SMTP connectors are planned. This guide documents the intended architecture and the provider requirements a production release must satisfy.

Build with us

Does this match the workflow your users need?

DewEngine is in development. Real use cases decide what ships first.

Share your use case