How to receive and parse email with Cloud Functions?

a 夏天 提交于 2020-01-13 16:27:30

问题


Google Cloud Functions allows you to easily activate a function upon a trigger (eg Firebase data change, HTTP request...).

I am looking for a way to execute a function when a user sends (or typically replies) to a email address. For instance, my dashboard sends an email, I would like to catch the reply, parse the content and upload it to Firebase as a comment in my Dashboard.

I understand that Google recommends to use Sendgrid. I however don't understand: - How to setup the trigger upon a reply - How to read the content and set the reading

I only found how to send emails here


回答1:


One option if you use GSuite is to use the Gmail watch mechanism to listen to new emails in your inbox. The message can then be posted to a PubSub topic which can trigger a Cloud Function to parse the email and perform your necessary next steps.

Here is a good use case that explains this mechanism
https://cloud.google.com/blog/products/application-development/adding-custom-intelligence-to-gmail-with-serverless-on-gcp




回答2:


Google Cloud Functions does not provide a permanent listener on an endpoint. There is also no event source for SMTP, which is the protocols involved with email delivery. So you can't simple respond to emails as they come in with Cloud Functions at the moment.

What you can do is direct the traffic to an existing SMTP server, and then use Cloud Functions to read from there at an interval.

An alternative is to use the Sendgrid Inbound Email API, which can call a webhook for every message it receives. And your webhook would then be a HTTP triggered Cloud Function.



来源:https://stackoverflow.com/questions/54544628/how-to-receive-and-parse-email-with-cloud-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!