SendGrid 无法发送电子邮件,firebase 功能。 (代码:403)

SendGrid unable to send email, firebase functions. (code: 403)

我正在使用 Firebase Functions 来托管 SendGrid 实施,但我无法发送不在 SendGrid 的“单一发件人验证”列表中的电子邮件.

我在尝试从 randomemail@gmail.com 发送电子邮件时遇到以下错误:

at node_modules/@sendgrid/client/src/classes/client.js:146:29 at processTicksAndRejections (internal/process/task_queues.js:95:5) code: 403

我可以发送我在 SendGrid 中添加到 Single Sender Verification list 的电子邮件。

这是我的firebase函数实现,请帮忙。我认为问题与域交叉来源或 SandGrid.

相关
import * as functions from "firebase-functions";
const sgMail = require("@sendgrid/mail");

exports.emailMessage = functions.https.onCall((data) => {
    sgMail.setApiKey("my key is here");

   const msg = {
    to: 'stanmozolevskiy@gmail.com', //here is one of the emails that I added to the Singlie Sender verification
    from: data.sender, // only works with email from 
    subject: `${data.name} sent you email`,
    text: data.message,
    html: `<strong>${data.message}</strong>`,
  }
  sgMail
    .send(msg)
    .then(() => {
      console.log('Email sent');
    })
    .catch((error:any) => {
      console.error(error);
    })
    return{"status": "sucess", data: data};
});

I am getting (the following) error when trying to send email from randomemail@gmail.com:

...

I am able to send the emails from the emails that I added to the Single Sender Verification list in the SendGrid.

这很正常,Sendgrid 只允许从经过验证的电子邮件发送电子邮件,以避免潜在的恶意用户以其他人的名义(即“在邮件中”)发送电子邮件。


请注意,如果您的发件人地址来自同一电子邮件域,您可以执行 Domain Authentication 并避免注册该域的每个电子邮件地址。

Sendgrid 只允许从经过验证的电子邮件发送电子邮件,但您可以使用 replyTo 属性 来解决问题。

const msg = {
    to: verifiedEmail,
    from: verifiedEmail,
    **replyTo: data.sender,** 
    subject: `${data.name} sent you email`,
    text: data.message,
    html: `<strong>${data.message}</strong>`,
  }