未收到来自 SendGrid 的电子邮件

Not receiving email from 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));
    }

感谢您抽出宝贵时间尝试提供帮助!

尝试提供主题、文字或html

 subject: 'Just testing subject',
  text: 'body text',
  html: '<strong>body text</strong>'

问题已解决:

我更彻底地研究了 SendGrid 文档。我在 Email Activity 页面上发现了我的问题。我看到我的电子邮件没有丢失,只是没有送达

我点击了电子邮件的日志,这是我看到的错误:

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 中进行身份验证。我需要完成 Sender Authentication 才能使用来自已注册域的电子邮件来证明我确实拥有该域。