"UnhandledPromiseRejectionWarning: Error: Forbidden" while sending email from sendGrid in Node.js

I was also facing the similar issue. I think they need to update the docs. The send method returns a promise that you have not handled that's why you're getting the error.

change

sgMail.send(msg)

to

sgMail.send(msg).then(() => {
    console.log('Message sent')
}).catch((error) => {
    console.log(error.response.body)
    // console.log(error.response.body.errors[0].message)
})

Now, the unhandled promise rejection error will be gone, And you'll get the error why the promise was being rejected.

Something like

The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements

It's pretty self-explanatory. Go to the specified link, and it'll guide you to verify the self identity. Once you complete that, It should work fine.


Links https://sendgrid.com/docs/ui/sending-email/sender-verification/