I’m trying to set up automatic notifications when new messages arrive in my inbox, but the webhook isn’t getting triggered. I followed all the setup steps but something isn’t working right.
What I’ve done so far:
Set up a Pub/Sub topic in my Google Cloud project
Gave the Gmail service account ([email protected]) publisher permissions on the topic
Created a push subscription pointing to my server endpoint
Verified my webhook URL works by sending test messages through Pub/Sub directly
The weird thing is that manual testing works fine, but when I actually receive emails in my Gmail account, nothing gets sent to my webhook endpoint.
Check your subscription acknowledgment settings. Gmail sends push notifications to your Pub/Sub topic, but your subscription must acknowledge each message within the ack deadline (defaults to 10 seconds). If your webhook doesn’t properly acknowledge the message, Pub/Sub thinks delivery failed and throttles future deliveries. Your webhook needs to return a 200 status code AND your subscription’s ack deadline should match your processing time. Also verify you’re actually getting messages in the Pub/Sub topic - go to the monitoring tab in Google Cloud Console and see if messages show up when emails arrive. If no messages reach the topic at all, you’ve got a problem with Gmail API permissions or the watch request.
Had the same issue - drove me nuts for weeks. Gmail’s watch request expires after 7 days by default, and it’s not obvious. You need to manually renew it or set up auto-renewal. Test this by calling users.stop() then a fresh users.watch() request. If notifications start working again, that’s your problem. I set up a cron job that renews every 5 days to stay ahead of it. Also make sure your webhook returns a 200 status within 10 seconds. Gmail’s push service is strict about response times and will stop sending notifications if your endpoint’s too slow or throws errors.
check if google’s servers can actually reach ur webhook endpoint. I had this same issue - turns out my local dev server wasn’t publicly accessible even tho I thought it was. Use ngrok or deploy to a real server to test. Also make sure ur pub/sub topic name matches exactly what u used in the watch request - typos there fail silently.