Use Cloud Pub/Sub to trigger sending of email - google-app-engine

I'm trying to figure out how to use Cloud Pub/Sub to trigger the sending of an email when a file is added to a storage bucket.
Currently using PHP72 in Google App Engine standard environment. First I created a Topic that creates a message when a file is added to the storage bucket. Then I created a Pull subscription which reads the message. I can view the messages in the GCP console, but what I would like to happen is that I want to be notified by email, preferably with a copy of the file added to the email as an attachment. Is this possible? I tried looking for a solution or tutorial but came up empty.

You can implement the send mail login in a cloud function which will be triggered by Pub/Sub (Node.js,Python,Go).
Using Pub/Sub to trigger a Cloud Function

Instead of using a pull subscription, you should probably use a push subscription with App Engine, combined with one of the third party mail services such as Send Grid or MailJet.
The upload of an object to GCS triggers a message to be sent to the topic, and the push subscription delivers that message to App Engine.
Unfortunately, there aren't any full tutorials asking for exactly what you want, but hopefully this helps. Feel free to request a community tutorial for this by filing an issue on the GCP community toturial repo.

Related

Is using Google Pub/Sub possible on the frontend (React)

I'm fairly new to things that aren't strictly front end, so after reading the Google pub/sub docs and doing a few searches its not clear to me whether using it with react is possible.
My use case is I (hypothetically) have tens of thousands of people on my webpage at a time that all need to be told at the same time that some external event occurred (the message would be very small).
I know Google Firestore has a listener feature but based on this specification it would not be within the free tier usage anymore. I've seen libraries that allow Google Pub/Sub to be used with IOT devices so I'm confused on why I can't find any resources on using it in the browser.
Creating a Cloud Pub/Sub subscriber in the frontend would be an anti-pattern for several reasons. First of all, the quota limits only allow 10,000 subscriptions per topic. Since you say you have tens of thousands of people on the web page at a time, you would not be able to create enough subscriptions for this case. Additionally, subscriptions created when users come to the website would not be able to get any notifications from before the time the subscription was created; Cloud Pub/Sub only guarantees delivery of messages published after the subscription was successfully created. Finally, you'd have the issue of security and authentication. In order to start a subscriber from the client, you'd need to pass it credentials that it could use. If you use separate credentials for each webpage viewer, then you'd have to create these credentials on the fly and revoke them when the user disappears. If you use the same credentials across all of the subscribers, then one subscriber could intercept the feed of another subscriber.
Overall, Cloud Pub/Sub is designed for the torrents use case: fewer feeds with a lot of data that has to be processed by fewer subscribers. What you are talking about is the trickles use case: a small number of messages that need to be distributed among a large number of subscribers with individual ACLs. Firebase Cloud Messaging is the product designed for this latter case.
While it is true that Cloud Pub/Sub is on the path for Google Cloud IoT, it is used on the publish side: many devices send their events to a topic that can be processed by subscribers. Note that these messages from devices don't come directly into Cloud Pub/Sub; they go through a Cloud IoT server and that server is what publishes the messages to Cloud Pub/Sub. Device authentication is done via Cloud IoT and not via permissions on Cloud Pub/Sub topics. The delivery of messages to IoT devices is not done with Cloud Pub/Sub.

Calling watch a second time on a different PubSub and client ID cancels the previous one

We are developing an app that uses the Gmail API to synchronize the e-mails of our users. We are relying on watch to get change notifications through a PubSub, as recommended in the documentation.
Everything is okay, and we are receiving the notifications correctly.
However, as many software companies, we do have a staging environment to test our new features. We have a staging Google OAuth2 client with different Client ID / Client Secret to authenticate to Google, and a staging PubSub topic/subscription to receive notifications.
If I connect my Gmail account on the staging environment, everything works fine. I receive the notifications in staging. If I connect after that the same Gmail account on the production environment, I receive the notifications in production ; but the staging notifications stops coming. The same happens the other way round.
I thought that by using a different client and a different PubSub, we could get the notifications in both environments. It doesn't seem the case. Maybe Google limits the subscription per Google Cloud project?
Does anyone have already met this limitation or have more information about this?
Best regards,
François Voron

Is there a limit on how many files can be dynamically generated on Google Cloud Storage?

I have an app that uses appengine and Twilio to send voice messages.
In order to send a voice message you have to have your message content in a publicly available XML file. My app has a form that allows the user to create and post a message. Once the user posts the message, my app will dynamically create the XML file and save it to a bucket in Google Cloud Storage (GCS).
It appears that this can work up to ten times only. On the eleventh attempt, CGS does not generate and save the file. When Twilio tries to make the voice call, it just craps out with a 404 error because GCS never created the file. If I delete some of the files in my bucket, it'll start working again.
I can't find any documentation on Google regarding this kind of limitation. Does anyone know if there is such a limitation?
Thanks

Google Cloud Send Email Upon File Upload

I'm new to Google Cloud, I'm trying to find out is there a way where everytime I upload a file to the Cloud Storage I can have an instance send an email to the user? I already have my device uploading files to Cloud Storage without any issues, however the device is also sending the emails to - and since it's an embedded application I'd prefer to off load that task.
Check out GCS Object change notifications. Its the more generic answer for "how do I take action when a file changes in GCS", but you could certainly implement a notification handler in appengine to handle your email notifications.

Sending daily message via GCM server on google app engine

I am trying to perform following.
I have deployed Google App Engine Server on Google App Engine.
Created dailyMessage.html within Web-INF at WEB-INF/data/dailyMessage.html
Trying to send the content of dailyMessage.html as Payload message.
However i have to upload this data file on daily basis to send updated message everyday. Is there any other way to achieve this functionality? I tried to explore for BlobStore functionality. However i didn't get the way i can upload and replace the file and access it via HTTP URL. Any help to achieve above functionality would be appreciable.
It sounds like you're manually creating the daily message, if so create a POST handler that allows you to POST the daily message.
Otherwise, if it's automatically generated, use a cron job that generates the message and sends it.

Resources