Recently, I have been using sendgrid api and I want to send email with single sender from my nodejs express server.
Code reference:
import sgMail from "@sendgrid/mail";
require("dotenv").config();
sgMail.setApiKey(process.env.SENDGRID_API_KEY as string);
async function sendEmail(email: string, token: string) {
const message = {
to: email,
from: {
name: "Hello World",
email: process.env.SENDGRID_API_EMAIL as string, // xxx@gmail.com (sender auth verified)
},
subject: "Hello World",
text: "Hello World",
};
return await sgMail.send(message);
}
When I trigger the sendEmail function, I could not receive the email!!!
result returned:
[
Response {
statusCode: 202,
body: '',
headers: {
server: 'nginx',
date: 'Tue, 17 Jan 2023 05:55:44 GMT',
'content-length': '0',
connection: 'close',
'x-message-id': xxx,
'access-control-allow-origin': 'https://sendgrid.api-docs.io',
'access-control-allow-methods': 'POST',
'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
'access-control-max-age': '600',
'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
'strict-transport-security': 'max-age=600; includeSubDomains'
}
},
''
]
Then, I checked out the sendgrid activity page and the event had not been displayed yet.
After like 5-20 minutes, the event was finally displayed on the activity page. However, my email address didn't received the email, and it turns out that the email has been "processed" but "not received by gmail.com".
Please click here to view the activity page: event details on the sendgrid activity page
Please tell me if you know the problem, thanks