0
votes

I have a Pub/Sub topic where I publish messages and that pubsub topic is subscribed by a Google Cloud Function which sends the email to the customer using mailgun API.

This works fine so far, now I got the requirement that I have to send the email with the file attachment.

I can easily do this using Google Cloud Function using HTTP trigger but how to do it using a Pub/Sub topic?

Check the given image.

enter image description here

Note: The file size could be more than 10mb in my case.

1
Can you share your existing code ("I can easily do this using Google Cloud Function using HTTP trigger")?Renaud Tarnec

1 Answers

1
votes

First of all if I understand your goal correctly, PubSub alone will never be enough as the actual work will happen at the function.

To achieve the above you need a cloud function with Pub/Sub trigger.

Once the function is called, you need to either fetch the attachment from a Google Cloud Bucket, or download it from a another API/source you have. You'll have to download it inside the /tmp directory which is used to store temporary files.

Once completed, then you can use mailgun or other tools of your choice. Remember the attachment is inside the /tmp directory and not ./

Using mailgun or any other method does not change anything on the overall approach. For example if you were to use Gmail API, you'd add this to your cloud function for the final step.