使用Sendgrid,Node.js和Firebase云功能,我能够通过http发送电子邮件。在过去的几天里,我的电子邮件不再发送了。我没有真正更改我的代码,所以我不知道是什么原因导致电子邮件无法发送。我检查了Firebase功能日志,但收到200或204状态代码。当我检查sendgrid时,它表明正在发出请求,并且正在发送电子邮件。
是的,我检查了我的垃圾邮件文件夹。
有人可以帮忙吗?
这是我的职能:
depart
这是我的组件。
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));
});
});
感谢您抽出宝贵的时间来尝试和帮助!
答案 0 :(得分:0)
尝试提供主题,文本或html
subject: 'Just testing subject',
text: 'body text',
html: '<strong>body text</strong>'
答案 1 :(得分:0)
问题已解决:
我更彻底地研究了SendGrid文档。我在Email Activity页上发现了问题。我看到我的电子邮件并没有丢失,只是没有被发送
我单击了电子邮件的日志,这是我看到的错误:
<div class="fixed-table-container">
<div class="header-background"> </div>
<div class="fixed-table-container-inner extrawrap">
<table cellpadding="5" style="font-family:arial; font-size:12px; width:100%;">
<thead>
<tr>
<th class="first">
<div class="th-inner"><a href="z.pl?sort=0">A</a></div>
</th>
<th>
<div class="th-inner"><a href="z.pl?sort=1">B</a></div>
</th>
<th>
<div class="th-inner">C</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">D</div>
</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">E</div>
</div>
</th>
<th>
<div class="th-inner">F</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">G</div>
</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">H</div>
</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">I</div>
</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;">J</div>
</div>
</th>
<th>
<div style="margin:0 auto; width:0;">
<div class="th-inner" style="width:100%; margin-left:-50%; text-align:center;"><a href="z.pl?sort=2">K</a></div>
</div>
</th>
</tr>
</thead>
我从中发送电子邮件的电子邮件地址未在SendGrid中进行身份验证。我需要完成Sender Authentication才能使用来自注册域的电子邮件,证明我确实拥有该域。