[英]Problem on sending email with firebase functions
我用 android 和 firebase 创建了一个商店应用程序。 我现在正在开发的是在存储桶上创建订单发票时向客户发送 email 的触发器。
我已经测试了与触发器相关的所有代码都是正确的,但是我遇到了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 帐户中,确保您启用了两步验证。
然后 go 到https://security.google.com/settings/security/apppasswords 。 单击 Select 应用程序并从下拉列表中选择其他(自定义名称),然后单击生成。 您将获得一个 16 位代码,此代码应用作 email 配置中的密码,用户仍为您的 email。 另外,确保 {secure: true}
这是我的配置:
transport: {
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '<myemail>',
pass: '<16 digit code generated in step 2 above>',
},
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.