I am sending an email to a person whose data is updated which is stored in google firestore, using cloud functions. I am using sendgrid to send email.
My cloud function is working fine, whenever I update the data it gets triggered. But I am unable to send email.
const sendgridemail = require('@sendgrid/mail');
const MY_SENDGRID_API_KEY = '<API key>'
sendgridemail.setApiKey(MY_SENDGRID_API_KEY);
exports.helloFirestore = (event, callback) => {
const triggerResource = event.resource;
console.log('Function triggered by change to: ' + triggerResource);
console.log(JSON.stringify(event));
const msgbody = {
to: '[email protected]',
from: '[email protected]',
subject: 'database updated - xyzshopping.com',
templateId: '<template ID>',
}
return helloFirestore.send(msgbody)
.then(() => console.log('payment mail sent success') )
.catch(err => console.log(err) )
callback();
};
I have deployed the code from console using inline editor and zip upload also. It is getting triggered but not sending email.It is throwing me error:
Error: getaddrinfo ENOTFOUND api.sendgrid.com api.sendgrid.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'api.sendgrid.com', host: 'api.sendgrid.com', port: 443