node.js - 未收到来自 SendGrid 的电子邮件
问题描述
使用 Sendgrid、Node.js 和 Firebase 云功能,我能够通过 http 发送电子邮件。在过去的几天里,我的电子邮件不再通过了。我并没有真正改变我的代码,所以我不知道是什么导致电子邮件无法发送。我检查了我的 firebase 功能日志,但收到 200 或 204 状态码。当我检查 sendgrid 时,它显示正在发出请求并正在发送电子邮件。
是的,我检查了我的垃圾邮件文件夹。
有人可以帮忙吗?
这是我的功能:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const cors = require("cors")({ origin: true });
const SENDGRID_API_KEY =
"SENDGRID-APIKEY";
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(SENDGRID_API_KEY);
exports.httpManagerEmail = functions.https.onRequest((req, res) => {
cors(req, res, () => {
const toEmail = req.body.toEmail;
const managerName = req.body.managerName;
const managerEmail = req.body.managerEmail;
const managerUUID = req.body.managerUUID;
const msg = {
to: toEmail,
from: {
email: "support@BLAH.com",
name: "BLAH"
},
text: '',
html: '',
templateId: "d-111111111",
substitutionWrappers: ["{{", "}}"],
substitutions: {
managerName: managerName,
managerEmail: managerEmail,
managerUUID: managerUUID
}
};
return sgMail
.send(msg)
.then(() => res.status(200).send({ message: "email sent!" }))
.catch(err => res.status(400).send(err));
});
});
这是我的 component.ts
endpoint = "MY_ENDPOINT"
sendEmail() {
const managerData = {
toEmail: this.manager.managerEmail,
managerName: this.manager.managerFirstName,
managerEmail: this.manager.managerEmail,
managerUUID: this.manager.managerUUID
}
this.httpClient.post(this.endpoint, managerData).subscribe(data => console.log('email sent: ', data));
}
感谢您花时间尝试和帮助!
解决方案
问题解决了:
我更彻底地调查了 SendGrid 文档。我在电子邮件活动页面上发现了我的问题。我看到我的电子邮件没有丢失,只是没有送达
我点击了电子邮件日志,这是我看到的错误:
550 5.7.1 Unauthenticated email from mydomain.com is not accepted
due to domain's DMARC policy. Please contact the administrator of
mydomain.com domain if this was a legitimate mail.
Please visit https://support.google.com/mail/answer/2451690 to learn about the
DMARC initiative. s5si11407114ywe.292 - gsmtp
我发送电子邮件的电子邮件地址未在 SendGrid 中进行身份验证。我需要完成发件人身份验证才能使用来自已注册域的电子邮件来证明我实际拥有该域。
推荐阅读
- python - 通过 pip 在 WSL2 上未正确安装 Cfgrib
- python - 在 Python 的算法交易中使用 IB / TWS 的最佳方式是什么?
- extjs - 如何更改 extjs 中 PayPal 按钮的金额值?
- google-cloud-platform - 如何知道 GCP 存储桶中是否存在路径“gs://bucket1/folder_x”
- neo4j - Neo4j 数据库不会加载到我在 Windows 上的桌面应用程序中
- angular - 使用 AuthGaurd 重定向后,Angular router.navigate() 不起作用
- amazon-web-services - 过滤器不过滤 Terraform 中的子网
- javascript - 变量值在内部发生变化,事件处理程序在外部给出未定义
- python - ValueError:输入 0 层 bidirectional_1 与层不兼容:预期 ndim=3,发现 ndim=2。收到的完整形状:(13、64)
- python - 生成特定日期的年龄