AWS + SendGrid not working
Closed this issue · 2 comments
jellohouse commented
Hi I'm using sendgrid with NextJs (and it's built in NodeJS backend API).
The code runs well on my local version, but not on the live version hosted on AWS amplify.
I made sure the .env variables are set properly on both environments with the same API key.
This code works well on my local version of the project and I get the email to my inbox.
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
function sendWelcomeEmail(email) {
const msg = {
to: email,
from: 'myverifiedemail@example.com,
template_id: 'd-26819a2291414e63dd54191fe2g43ba9'
}
sgMail
.send(msg)
.then(() => {
console.log('Done! Email sent');
return;
})
.catch((error) => {
console.error('Hmmm error!', error)
return error;
})
}
// The API endpoint
export default async (req, res) => {
if(req.method === 'POST') {
const { email } = req.body;
await sendWelcomeEmail({ email });
return res.status(200).end();
}
return res.status(404).json({
error: {
code: 'not_found',
messgae: "The requested endpoint was not found or doesn't support this method."
}
});
}
There is a similar issue here #1233 but the solution is to verify the sender email in Sendgrid which I have already done...
So I'm not too sure what the problem might be - Any help would be greatly appreciated!
childish-sambino commented
Could you provide more details on the error(s) you're seeing?
JenniferMah commented
Closing due to inactivity. Please re-open this issue or open a new GitHub issue if you still need help.