Using @sendgrid/email in a Netlify function does not send the email. The send(msg) command returns neither a success nor an error. Nothing seems to be fired.
Steps to Reproduce
Setup a Netlify Function with the "hello email" example provided by sendgrid
Deploy the site to Netlify
fire the Netlify function
Code Snippet
const sendgrid = require('@sendgrid/mail');
sendgrid.setApiKey(process.env.SENDGRID_API_KEY);
const handler = async (event) => {
const msg = {
to: 'nicolas@luchier.fr',
from: 'nicolas@luchier.fr', // Use the email address or domain you verified above
subject: 'Sending with Twilio SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sendgrid
.send(msg)
.then(() => {console.log('hop !')}, error => {
console.log(error);
if (error.response) {
console.log(error.response.body)
}
});
return {
statusCode: 200,
body: JSON.stringify({ retour: "ok"}),
// // more keys you can return:
// headers: { "headerName": "headerValue", ... },
// isBase64Encoded: true,
}
}
module.exports = { handler }
I verified that the SENDGRID_API_KEY has the correct key. No error fired but no email sent. It works in local development... I am not sure of the difference.
Exception/Log
No log output, neither console.log("hop") nor the error message
Issue Summary
Using @sendgrid/email in a Netlify function does not send the email. The send(msg) command returns neither a success nor an error. Nothing seems to be fired.
Steps to Reproduce
Code Snippet
I verified that the SENDGRID_API_KEY has the correct key. No error fired but no email sent. It works in local development... I am not sure of the difference.
Exception/Log
Technical details:
Any help would be really appreciated. I am also posting this to the Netlify forum.
Thanks, Nicolas