Gmail

Communication OAuth Windmill docs

Send email with attachments, search, read, label and draft from any Windmill script, flow or app — save attachments to object storage, trigger a flow on new mail, or pause one until someone clicks an approval link in their inbox.

What you can do with Gmail

Complete, deployable projects built around Gmail — the fastest way to get something real running.

Set up in 2 steps

1

Connect from the Resources page

Open Resources, click Add a resource/API and pick gmail from the OAuth APIs list. Click Connect and sign in with the Google account the mail should be sent from, then name the resource and save it.

2

Run your first script

Fork the send email script below, or drop the approval step into a flow to have it wait on a reply.

Scripts

Building blocks, if none of the projects above fit. Fork one, run it, or call it as a step inside your own flow.

Submit a script →

Flows

Multi-step workflows that already wire Gmail to something else.

All flows →

Trigger flows from Gmail

Gmail is not only a destination. These inbound paths are supported today.

New email (scheduled poll)

The New Email trigger script polls the mailbox and returns the messages matching a search query since its last run. It needs gmail.readonly or gmail.modify on the connection. To run it, open a flow, add a trigger and choose Scheduled Poll, then pick the trigger script and an interval. Windmill puts the script first in the flow with a loop after it, so the steps you add run once per new item. The cursor is saved per flow: two flows polling the same source each get every item, and test runs keep a cursor of their own.

Instant push (Pub/Sub in your own Google Cloud project)

Gmail only pushes to a Pub/Sub topic you own, which is why the trigger above polls. For instant delivery, create a topic in your Google Cloud project, grant [email protected] the Pub/Sub Publisher role on it, call users.watch with the topic name, and attach Windmill's GCP Pub/Sub trigger (a self-hosted Enterprise feature) to a subscription on that topic. Each notification carries only the mailbox address and a historyId, so the handler calls users.history.list to fetch what changed. users.watch expires after 7 days: call it again daily from a schedule.

Resource type

The shape of the credential every script on this page expects.

FieldTypeRequiredWhat it is
tokenstringYes

Questions

What can Windmill do with my mailbox?

Whatever scope you grant when connecting. The default, gmail.send, only lets scripts send mail (attachments, aliases and thread replies included). Searching, reading, downloading attachments, listing send-as aliases, the profile and the new-email trigger need gmail.readonly or gmail.modify; drafts need gmail.compose or gmail.modify; labelling messages needs gmail.modify, and creating or deleting labels needs gmail.labels or gmail.modify. gmail.modify covers every script, send included, but not permanent deletion. Tick the scope in the connect dialog, or reconnect an existing resource to change it.

Can I create the resource by hand instead of connecting?

Nothing stops you — the resource is a single token field. But there is no long-lived Gmail API token: Google's access tokens last about an hour, and only the OAuth flow returns the refresh token that renews them, which is why this page has no CLI lane. For a credential that does not expire, send through the separate smtp resource instead.

There is no Connect button on my instance

Self-hosted instances need a Google OAuth client configured once by an admin before the tile appears.