Kirill Barkunov
Kirill Barkunov

Reputation: 113

How to get new message detailes via Gmail push notifications?

I have java server application. And I need to monitor a lot of gmail accounts to be able to send push notifications to mobile devices about new Inbox messages. I need to know sender email and message subject to send push notification.

And I tried Gmail push notifications system (webhooks option) If I understood everything correctly in order to get needed info for each new message for each user there is a following scenario:

That means that I need 2 additional requests for each new message of each user. And it looks quite hard if server needs to handle several new messages each second. And I still don't see other way.

Is there any way to make it shorter? (e.g. to make google send me not only history id but needed new message details or at least make one additional request, but not two)

Thanks!

Upvotes: 5

Views: 2019

Answers (2)

Shailendra
Shailendra

Reputation: 1

I was facing the same problem. History API was not giving recent messageId. I solved this problem by hitting THREAD API where i set Q = last 5 min timestamp. Webhook push notification is helping to notify a new mail has come. After i get all messages last 10 min with THREAD API.

Upvotes: 0

PNC
PNC

Reputation: 1972

We tried using Push notifications but the volume of requests generated has meant that we poll on a timed basis instead. It is worth noting that you will get Push notifications for any change to the message such as a label change, a read status change etc. As you say there are many requests.

If you need the notifications real-time I don't see how you can avoid the process that you outline.

If you don't need it real-time then you can poll or at the least check for Push notifications per account on a timed basis and if some have been received retrieve any new messages in a batch rather than a single request.

Upvotes: 1

Related Questions