2
votes

I'm using the Gmail API (With the Google Cloud Platform) to send push notifications to my server. This mailbox is never actually accessed by a user, it only exists for the purpose of sending push notifications to a route on my server that retrieves the latest email from the mailbox.

Everyday, I have a cron job that renews the Users: watch() on this email address. It's only one email address associated with a single topic in the Cloud Console with one push subscription to my server. My controller then calls Users.messages: list to get a list of recent emails, followed by Users.messages: get to get the most recent email with all attachment IDs/filenames, and finally Users.messages.attachments: get to get each data for each attachment.

I've noticed that when I send emails with lots of attachment data (25 Mb of image data for instance), I start receiving a series of push notifications, each with the same message_id and timestamp in the data sent with the push notification POST request. For now, I'm dealing with this by saving the message_id in a cache for a little while to prevent my server from reacting to a single push notification more than once.

Although my solution works nicely, I'm curious if anyone else has experienced a problem like this, or whether this is a bug in the Gmail API or Cloud Platform. Any help or advice is appreciated!

1
I see similar behavior, too many notifications, for every possible action, email received, removed, opened, archived, the label added, label removed, ...Igor G.

1 Answers

0
votes

I don't think it's a bug in Gmail or in Cloud Platform.

Actually, as discussed in Push Notifications, Gmail API have already implemented the use of Cloud Pub/Sub API to deliver push notifications. This allows notification via a variety of methods including webhooks and polling on a single subscription endpoint. And, with this API, using a single topic for all Gmail API push notifications for all application is recommended.

Detailed information can be found in the documentation and to get familiarized with this Cloud Pub/Sub API, I suggest that you go through Google Cloud Pub/Sub Documentation.