Advanced: Google Cloud setup for Gmail push
This is an advanced reference for administrators. Most setups do not need it. The everyday page is Enable faster Gmail synchronization.
This page shows every Google Cloud resource that Gmail push needs, so you can see what the generated script creates or build it by hand.
Who this is for: Google Cloud administrators who set up Gmail push for MailDesk.
You need: MailDesk Pro, a Google Cloud project you can administer, and the gcloud command line (Google Cloud Shell has it).
Everything is in your own project
MailDesk creates nothing in Google Cloud and holds no Google credentials of its own. Every resource below is created in, owned by and billed to your project. MailDesk stores three non-secret values (project id, topic name, signer email) and the webhook settings it needs to verify notifications.
| Resource | Where | Owner |
|---|---|---|
| Enabled APIs, Pub/Sub topic, IAM grant, signer service account, push subscription | Your Google Cloud project | You |
The webhook endpoint /maildesk/push/gmail |
Your Odoo server | You |
| Project id, topic name, signer email | Stored in MailDesk | You |
What you build
The generated script runs six numbered phases. The steps below follow the same order.
| Step | Phase | What |
|---|---|---|
| A | 1/6 | Select the project that owns your Gmail OAuth client |
| B | 2/6 | Enable the Gmail API and the Pub/Sub API |
| C | 3/6 | Create the Pub/Sub topic |
| D | 4/6 | Let Gmail publish to the topic |
| E | 5/6 | Create the signer service account |
| F | 6/6 | Create the push subscription |
Step A: Pick the project that owns your OAuth client
Gmail requires the Pub/Sub topic to be in the same Google Cloud project as the OAuth client your mailbox uses. Otherwise validation fails with WATCH_400_TOPIC_PROJECT_MISMATCH.
Do not create a new project for the topic
Use the project of your Gmail OAuth client, unless that project is also where the client lives. If you connected the mailbox through Connect Gmail / Google Workspace, use that project.
gcloud config set project <oauth-client-project>
To find the project, open https://console.cloud.google.com/apis/credentials and read the project selector at the top. If a topic already exists in another project, run the setup script with PROJECT_ID set to the OAuth client's project and paste the new topic name into the assistant.
Step B: Enable the APIs
gcloud services enable gmail.googleapis.com pubsub.googleapis.com
You can also use https://console.cloud.google.com/apis/library.
Wait a moment after enabling
A new API may take 30 to 60 seconds to work. If the watch fails with WATCH_403_GMAIL_API_NOT_ENABLED right after, wait and try again.
Step C: Create the topic
gcloud pubsub topics describe maildesk-gmail-push >/dev/null 2>&1 \
|| gcloud pubsub topics create maildesk-gmail-push
The default topic name is maildesk-gmail-push. MailDesk needs the full name projects/<project-id>/topics/maildesk-gmail-push. Read it back with:
gcloud pubsub topics describe maildesk-gmail-push --format='value(name)'
Console: https://console.cloud.google.com/cloudpubsub/topic/list
Topic name format
The name must look like projects/<project-id>/topics/<topic-name>. Anything else fails as WATCH_400_BAD_TOPIC.
Step D: Let Gmail publish to the topic
Gmail publishes through a Google-owned service account, [email protected]. It needs the roles/pubsub.publisher role on your topic. Without it the watch fails with WATCH_403_TOPIC_IAM_MISSING.
gcloud pubsub topics add-iam-policy-binding maildesk-gmail-push \
--member='serviceAccount:[email protected]' \
--role='roles/pubsub.publisher'
Project-wide IAM: https://console.cloud.google.com/iam-admin/iam
Step E: Create the signer service account
Pub/Sub signs every push with an OIDC token so MailDesk can check that it came from your subscription. You create the signing identity:
gcloud iam service-accounts create maildesk-pubsub-push \
--display-name='MailDesk Pub/Sub push signer'
The default name is maildesk-pubsub-push, so the email is maildesk-pubsub-push@<project-id>.iam.gserviceaccount.com. Console: https://console.cloud.google.com/iam-admin/serviceaccounts
Paste the full email
The signer email must look like <name>@<project-id>.iam.gserviceaccount.com, in lowercase, with no display name or spaces. Otherwise validation fails as SIGNER_BAD_FORMAT. Copy it from gcloud iam service-accounts list.
Step F: Create the push subscription
Three values must be exactly right:
| Value | Setting |
|---|---|
| Push endpoint | <web.base.url>/maildesk/push/gmail |
| Push auth service account | The signer email from step E |
| Push auth token audience | The same text as the push endpoint, character for character |
gcloud pubsub subscriptions create maildesk-gmail-push-sub \
--topic=maildesk-gmail-push \
--push-endpoint='https://your-odoo-host/maildesk/push/gmail' \
--push-auth-service-account='maildesk-pubsub-push@<project-id>.iam.gserviceaccount.com' \
--push-auth-token-audience='https://your-odoo-host/maildesk/push/gmail' \
--ack-deadline=10
The default subscription name is maildesk-gmail-push-sub. The generated script uses an acknowledgement deadline of 10 seconds. If the subscription exists, the script updates its endpoint, signer and audience. Console: https://console.cloud.google.com/cloudpubsub/subscription/list
The audience must equal the endpoint
MailDesk's webhook only accepts a token whose audience equals the URL it was sent to. If they differ, validation stops at AUDIENCE_MISMATCH.
The address comes from web.base.url. It must be stable, public HTTPS with a valid certificate. See Set up HTTPS for faster synchronization.
The easy path: run the generated script
- In the assistant, choose Recommended mode and enter your project id. The assistant fills in the default names.
- Copy the script, open Google Cloud Shell (
https://shell.cloud.google.com/), paste it and run it. -
Copy the last line it prints:
MAILDESK_PUSH_RESULT={"project_id":"…","topic_name":"projects/…/topics/maildesk-gmail-push","signer_service_account_email":"maildesk-pubsub-push@….iam.gserviceaccount.com"}
The script checks each resource first and creates only what is missing, so you can run it again after a failure.
Paste the result into MailDesk
- In the Paste result step, paste the whole
MAILDESK_PUSH_RESULT=line and click Parse JSON. - MailDesk reads
project_id,topic_nameandsigner_service_account_email. - In Validate & enable, MailDesk checks the URL, the audience and the formats, saves the signer to the allow-list, and calls
users.watch.
If you built everything by hand, use Advanced mode and enter the same three values.
MailDesk then checks every incoming push: the OIDC signature, that the audience matches your URL, and that the signer is on the allow-list.
Console links in the assistant
The assistant offers shortcuts to the pages used above. Most are scoped to your project; the Cloud Shell link is not.
| Button | Page |
|---|---|
| Open APIs & Services | https://console.cloud.google.com/apis/library |
| Open Pub/Sub Topics | https://console.cloud.google.com/cloudpubsub/topic/list |
| Open Push Subscriptions | https://console.cloud.google.com/cloudpubsub/subscription/list |
| Open Service Accounts | https://console.cloud.google.com/iam-admin/serviceaccounts |
| Open IAM | https://console.cloud.google.com/iam-admin/iam |
| Open Google Cloud Shell | https://shell.cloud.google.com/ |
If it does not work
| Code | Meaning | Safe next step |
|---|---|---|
WATCH_400_TOPIC_PROJECT_MISMATCH |
The topic is in a different project than the OAuth client | Run the script with the OAuth client's project, then paste the new topic name |
WATCH_403_GMAIL_API_NOT_ENABLED |
The Gmail API is off | Run the enable command from step B, wait 30 to 60 seconds |
WATCH_403_TOPIC_IAM_MISSING |
Gmail's publisher account has no publisher role | Run the script again or the command from step D |
WATCH_400_BAD_TOPIC |
The topic name is malformed | Paste the value from the describe command |
WATCH_404_TOPIC_NOT_FOUND |
The topic does not exist | gcloud pubsub topics list --format='value(name)', then recreate or correct it |
SIGNER_BAD_FORMAT |
The signer email is malformed | Copy it from gcloud iam service-accounts list |
AUDIENCE_MISMATCH |
Audience differs from the webhook address | Run validation again and update the subscription audience in Google Cloud |
WATCH_401_OAUTH_INVALID |
The Gmail authorization expired or was revoked | Reconnect the mailbox, then open the assistant |
WATCH_400_OAUTH_SCOPE_MISSING |
The token lacks gmail.modify |
Disconnect and reconnect, accepting all scopes |
These errors only block push. Scheduled sync (about every 2 minutes for Gmail) keeps delivering mail. Details for each code: Fix Gmail synchronization setup errors.
After setup
- The watch renews itself. A Gmail watch lasts at most 7 days, and MailDesk renews it when less than 24 hours remain.
- If notifications stop for 6 hours, MailDesk requests a catch-up sync.
- There is no regular task in Google Cloud.