简体   繁体   English

SendGrid 无法发送 email、firebase 函数。 (代码:403)

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

I am using Firebase Functions to host the SendGrid implementation and I am not able to send emails with the emails that are not in the "Single Sender Verification" list in SendGrid .我正在使用Firebase Functions来托管SendGrid实现,并且我无法使用SendGrid中“单一发件人验证”列表中未包含的电子邮件发送电子邮件。

I am getting the following error when trying to send email from randomemail@gmail.com :尝试从randomemail@gmail.com发送 email 时出现以下错误:

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

I am able to send the emails from the emails that I added to the Single Sender Verification list in the SendGrid .我可以从添加到SendGrid中的单一发件人验证列表的电子邮件中发送电子邮件。

Here is my firebase function implementation, please help.这是我的 firebase function 实现,请帮助。 I think the problem is related to domain cross origin or something with SandGrid .我认为问题与域交叉起源或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:尝试从 randomemail@gmail.com 发送 email 时出现(以下)错误:

... ...

I am able to send the emails from the emails that I added to the Single Sender Verification list in the SendGrid.我能够从添加到 SendGrid 中的单一发件人验证列表的电子邮件中发送电子邮件。

This is normal, Sendgrid allows only emails sent from aa verified email, in order to avoid potential malicious users sending emails in the name (ie "in the mail") of someone else.这是正常的,Sendgrid 只允许从经过验证的 email 发送的电子邮件,以避免潜在的恶意用户以他人的名义(即“在邮件中”)发送电子邮件。


Note that if your sender addresses are coming from the same email domain you can do a Domain Authentication and avoid registering each email address of the domain.请注意,如果您的发件人地址来自同一个 email 域,您可以进行域身份验证并避免注册域的每个 email 地址。

Sendgrid allows only emails sent from aa verified email, but you can use the replyTo property in order to solve the problem. Sendgrid 只允许从经过验证的 email 发送的电子邮件,但您可以使用replyTo属性来解决问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM