node.js - 使用 firebase 功能发送电子邮件时出现问题
问题描述
我用 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);
});
}
}
如果有人可以帮助我,我将不胜感激。
解决方案
我遵循了通过@John Brookfields的链接上公开的解决方案。
对于要从 smtp.gmail.com 发送的邮件,请确保您已遵循以下 2 个步骤:
在您的 Google 帐户中,确保您启用了两步验证。
然后转到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>',
},
}
推荐阅读
- javascript - 我想让我的按钮在点击时转到我的页面顶部
- ios - iOS:检测设备是否为 iPhone X 系列(无框)
- cygwin - libFM:无法加载/保存模型
- javascript - ++ 在我的函数中没有添加正确的数字
- reactjs - 如何根据 redux store 的内容在 React Navigation 中动态指定屏幕?
- logging - 使用属性(.net 核心)测量方法执行时间
- java - 在开始路由之前交叉检查骆驼 ftp/sftp 身份验证
- php - 递归函数的PHP问题
- javascript - 在另一个对象内创建动态对象
- javascript - react setState中的传播运算符