how to write a Cloud Function for send email using SendGrid

江枫思渺然 提交于 2019-12-20 05:58:24

问题


I am trying to send email using sendGrid (In my mobile application). So i wrote a cloud function and deployed it into firebase.(using this,Visit https://angularfirebase.com/lessons/angular4-transactional-email-with-cloud-functions-and-sendgrid/).

it was uploaded to firebase. But, when i try to send post request(Using postman{"to":"user1@gmail.com","from":"duser253@gmail.com","subject":"test-email","content":"content"}), in firebase log shows some errors

SendGridError: Response error
at /user_code/node_modules/sendgrid/lib/sendgrid.js:104:23
at ClientRequest.<anonymous> (/user_code/node_modules/sendgrid/node_modules/sendgrid-rest/lib/client.js:124:7)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at connectErrorNT (net.js:1040:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
  message: 'Response error',
  response: 
   { statusCode: 500,
     body: 
      { message: 'getaddrinfo ENOTFOUND api.sendgrid.com api.sendgrid.com:443',
        name: 'Error',
        stack: 'Error: getaddrinfo ENOTFOUND api.sendgrid.com api.sendgrid.com:443\n    at errnoException (dns.js:28:10)\n    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)' },
     headers: {} } 

回答1:


You need to be on the "Flame" or "Blaze" pricing plan.

As a matter of fact, the free "Spark" plan "allows outbound network requests only to Google-owned services". See https://firebase.google.com/pricing/ (hover your mouse on the question mark situated after the "Cloud Functions" title)

Since Sendgrid is not a Google-owned service, you need to switch to the "Flame" or "Blaze" plan.



来源:https://stackoverflow.com/questions/52925963/how-to-write-a-cloud-function-for-send-email-using-sendgrid

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