首页 > 解决方案 > 未收到来自 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));
    }

感谢您花时间尝试和帮助!

标签: node.jsangularsendgridsendgrid-templates

解决方案


问题解决了:

我更彻底地调查了 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 中进行身份验证。我需要完成发件人身份验证才能使用来自已注册域的电子邮件来证明我实际拥有该域。


推荐阅读