1

When I tried to send an email from google function its throws following err

{ Error: getaddrinfo EAI_AGAIN api.sendgrid.com:443 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) errno: 'EAI_AGAIN', code: 'EAI_AGAIN', syscall: 'getaddrinfo', hostname: 'api.sendgrid.com', host: 'api.sendgrid.com', port: 443 }

But I tried exact same code on my local machine it works totally fine Here is my function

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(SENDGRID_API_KEY);

var sendMail = function (templateId, receivers, dynamicData, sender, mailSubject) {
var mailMsg ={
        to :receivers[0].email,
        from : sender[0].email ,
        subject : mailSubject,
        templateId : templateId,
        dynamic_template_data : dynamicData

    }

    sgMail.send(mailMsg).then(() => console.log("mail sent"))
        .catch(err => console.log(err));
}

Thank You in advance!!!!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Swapnil
  • 17
  • 4
  • This appears to be the same issue as in https://stackoverflow.com/questions/40182121/error-getaddrinfo-eai-again so see that discussion. – Richard Chambers Oct 07 '19 at 03:23
  • 3
    If you get this on Cloud Functions, is your project on the free/spark plan by any chance? To be able to call third-party APIs (such as SendGrid), your project will have to be on a paid plan. – Frank van Puffelen Oct 07 '19 at 03:34
  • @FrankvanPuffelen I have also got the same error when I am using SendGrid for the email whenever a new document is added in the collection. is it due to the free plan ? – Premjeet Kumar Feb 14 '20 at 06:48
  • Yes. As said: third-party APIs can only be called once you have a billing account associated with your project. – Frank van Puffelen Feb 14 '20 at 16:10

1 Answers1

0

This is another related question: link. See the discussion where it is said that the free "Spark" plan "allows outbound network requests only to Google-owned services".

marian.vladoi
  • 7,663
  • 1
  • 15
  • 29