0
votes

I am setting up push notifications for gmail based on the guide provided by google (https://developers.google.com/gmail/api/guides/push). I want to have my node app register a client with .watch(), and then receive emails at a specified endpoint, as described in the documentation.

I have created the pub/sub topic, added gmail as a publisher, added a subscriber, and called watch() in my node app. watch() returns the appropriate { historyId: xxxx, expiration: yyyy } object which, according to google's documentation, means the call succeeded.

handler for receiving email notification on backend:

export const receiveGmailEmail: RequestHandler = async (req, res) => {
  log('Received update from google!');
  log(JSON.stringify(req.body, null, 2));
  return res.status(200);
}

Registering:

  const watchRes = await gmailClient.watch();
  log('====> Watch Response <=====');
  log(JSON.stringify(watchRes, null, 2));

Server log that shows it is registering properly: ====> Watch Response <===== { "historyId": "6560", "expiration": "1562025255689" }

I never receive messages at the receive endpoint on my node app. According to the server logs, I never actually receive any request when a message is published. The problem appears to be that my messages are undelivered. I have confirmed through the Stackdriver monitor that the pub/sub topic is publishing messages when I send an email to the email address, but if I view the details of the subscription in Stackdriver, it shows an increasing number of undelivered messages.

Any thoughts on why messages in a subscription are sitting around undelivered?

1
Is the Pub/Sub subscription you configured during this step a pull subscription or a push subscription? developers.google.com/gmail/api/guides/… Can you check the subscription/pull_request_count and subscription/push_request_count metrics in Stackdriver? What response_codes are being recorded?Lauren
Hi Lauren! The subscription is set up as a push subscription The push_request_count metric is 1, and the response_class is remote_server_4xx and the response_code is 403 (Thanks for pointing this out, I didn't see it before!). Looking through the google docs, I think this means there's a permissions issue (cloud.google.com/pubsub/docs/reference/error-codes). I've verified that I have added a service account as a subscriber and gmail as the publisher in my topic. Is there something I need to do to tie the service account with my app besides just passing the topic name to watch?dbarton91
What endpoint is Pub/Sub pushing to? I am asking how you are mapping receiveGmailEmail to an HTTP endpoint that Pub/Sub is calling via HTTP Post.John Hanley
@Lauren, sorry, just realized I forgot to tag you in that previous comment!dbarton91
@JohnHanley, the route mapping on the node server is done in another file: const router = Router(); ... const post = router.post.bind(router); ... post('/emails/gmail/receive', receiveGmailEmail); But I think it's not even hitting my server because I don't see anything in my server logs on AWS. I would expect to at least see an incoming request that hit the server, even if I don't have a route to handle itdbarton91

1 Answers

0
votes

It turns out this wasn't a Google pub/sub issue. Amazon Cloudfront blocks POST requests by default, so I had to edit the caching behavior to enable POST requests. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesAllowedHTTPMethods