【问题标题】:SendGrid unable to send email, firebase functions. (code: 403)SendGrid 无法发送电子邮件、firebase 功能。 (代码:403)
【发布时间】:2022-01-19 14:07:15
【问题描述】:

我正在使用Firebase Functions 来托管SendGrid 实现,并且我无法使用SendGrid 中“单一发件人验证”列表中未包含的电子邮件发送电子邮件。

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

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

我能够从我添加到Single Sender Verification list 中的SendGrid 的电子邮件中发送电子邮件。

这是我的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};
});

【问题讨论】:

    标签: node.js firebase google-cloud-functions sendgrid


    【解决方案1】:

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

    ...

    我能够从我添加到 SendGrid 中的单一发件人验证列表。

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


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

    【讨论】:

    • 感谢您的回复 Renaud,我认为不是这样。即使我使用某人的电子邮件,我知道它是合法的,仍然会给我同样的错误。所以如果客户想给我发邮件,我需要把它们添加到 SendGrid 中的 Single Sender Verification 列表中吗? (听起来不对)
    • “即使我使用某人的电子邮件,我知道它是合法的”。我会有点“直接”=> 对于 Sendgrid 来说重要的是他们知道电子邮件是合法的,而不是你知道的。他们无法信任其服务的用户,因此他们需要验证用户是他/她在其服务中使用的所有发件人地址的所有者。
    • 我很确定情况并非如此,因为当我按照本教程 edwardbeazer.com/… 进行操作时,我能够正确设置它。但是教程示例不允许我传递参数,所以我不得不将其修改为我现在所拥有的。
    • 您可能对sendgrid.com/blog/dont-send-email-from-domains-you-dont-controldocs.sendgrid.com/ui/sending-email/sender-verification 感兴趣。请注意,如果您有 authenticated domain 并且您的发件人电子邮件地址与该域完全匹配,您的发件人身份将被自动验证
    • Twilio SendGrid 布道师在这里。 Renaud 是正确的,使用 SendGrid 时不能只从任何地址发送。您可以通过domain authenticationverify a single email address,但域身份验证更适合生产用途。
    【解决方案2】:

    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>`,
      }
    

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 2020-11-22
      • 2018-11-08
      • 2018-10-16
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      相关资源
      最近更新 更多