【问题标题】:Problem on sending email with firebase functions使用 firebase 功能发送电子邮件时出现问题
【发布时间】:2021-08-14 15:28:30
【问题描述】:

我创建了一个带有 android 和 firebase 的商店应用程序。我现在正在开发的是在存储桶上创建订单发票时向客户发送电子邮件的触发器。

我已经测试了与触发器相关的所有代码都是正确的,但是我遇到了sendMail 函数的问题。具体来说,Firebase Functions 控制台正在捕获 Error: Unexpected socket close

这是我的代码:

function sendEmail(user, email, order, type){
  console.log("Sending Email...");
  if (type == "confirmacionPedido"){
    return transport.sendMail({
      from: "COMPANY <xxxxxxx@gmail.com>",
      to: email,
      subject: "Confirmación pedido " + order,
      html: `
            <h1> Estiamdo ${user}, </h1>
            <p> Hemos recibido su pedido correctamente. Le mantendremos infromado de su estado. </p>
            <p> Gracias por confiar en nosotros </p>
          `
    })
    .then(r => r)
    .catch(e => {
      console.log(e);
    });
  }
}

如果有人可以帮助我,我将非常感激。

【问题讨论】:

  • 能否请您参考this并发表评论?

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


【解决方案1】:

我已按照已通过 @John Brookfields 的链接上公开的解决方案进行操作。

对于要从 smtp.gmail.com 发送的邮件,请确保您已遵循以下 2 个步骤:

  1. 确保在您的 Google 帐户中启用了两步验证。

  2. 然后转到https://security.google.com/settings/security/apppasswords。单击选择应用程序并从下拉列表中选择其他(自定义名称),然后单击生成。您将获得一个 16 位代码,此代码应用作电子邮件配置中的密码,并且用户仍然是您的电子邮件。另外,确保 {secure: true}

这是我的配置:

transport: {
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: '<myemail>',
        pass: '<16 digit code generated in step 2 above>',
    },
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 2020-11-22
    • 2011-07-30
    • 2018-11-15
    • 2020-07-13
    • 2021-06-18
    • 2011-10-28
    相关资源
    最近更新 更多