javascript - Nodemailer 自定义 SMTP 不适用于 Firebase 功能
问题描述
我有一个错误。我正在使用 nodemailer 从我的 Firebase 应用程序发送电子邮件。
这是我的代码的样子:
const functions = require('firebase-functions');
const admin = require("firebase-admin");
const nodemailer = require('nodemailer');
admin.initializeApp();
//THESE SETTINGS WORK ON LOCAL AND LIVE. BUT I DONT WANT TO USE THEM
// const transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: 'GMAIL HERE',
// pass: 'GMAIL PW HERE'
// },
// })
//THESE SETTINGS WORK ON LOCAL, BUT NOT ON LIVE.
const transporter = nodemailer.createTransport({
host: "smtp.mycompanyname.com",
port: 25,
secureConnection: false, // TLS requires secureConnection to be false
logger: true,
debug: true,
secure: false,
requireTLS: true,
auth: {
user: "USERNAME HERE",
pass: "PASSWORD HERE"
},
tls: { rejectUnauthorized: false }
})
exports.sendConfirmationEmail = functions.https.onCall((data, context) => {
var email_adress = data.data.email;
var email = {
from: 'E-Mail Adress Goes Here',
to: email_adress,
subject: 'BlaBlaBla',
text: 'BlaBlaBla',
html: 'BlaBlaBla'
};
// Function to send e-mail to the user
transporter.sendMail(email, function(err, info) {
if (err) {
console.log(err);
return { success: false };
} else {
return { success: true }
}
});
})
现在。如果我使用 GMail 设置。一切正常。它发送电子邮件。但是,我公司有自己的 SMTP 服务器。SMTP 适用于 Firebase 身份验证电子邮件。它正在成功发送这些电子邮件。
当我将上述配置粘贴到本地环境中时,SMTP 服务器也可以工作。但是,当我在 Firebase Cloud 函数中运行它时,会出现以下错误:
10:24:43.479 AM
sendConfirmationEmail
[2020-09-25 08:24:43] DEBUG [Cq6p67HnXLA] Closing connection to the server using "destroy"
10:24:43.479 AM
sendConfirmationEmail
[2020-09-25 08:24:43] ERROR Send Error: Connection timeout
10:24:44.673 AM
sendConfirmationEmail
{ Error: Connection timeout
10:24:44.673 AM
sendConfirmationEmail
at SMTPConnection._formatError (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
10:24:44.674 AM
sendConfirmationEmail
at SMTPConnection._onError (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:770:20)
10:24:44.674 AM
sendConfirmationEmail
at Timeout._connectionTimeout.setTimeout (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:235:22)
我尝试过使用不同的 nodemailer 选项,但到目前为止还没有取得很大的成功。这也使得它在本地很难工作,但是当我部署它时却没有。
有任何想法吗?
解决方案
推荐阅读
- python - How are elements across Rows(r) and columns (c) arranged in numpy?
- .net-core - .NET Core 5.0:Obfuscar 以代码 123 退出
- qt - QML:在 ScrollView 中向上展开 ColumnLayout?
- flutter - 如何在飞镖中将 x-www-form-urlencoded 字符串转换为 json?
- javascript - React useState 设置器如何在不使用状态变量的情况下更新此状态变量?
- c# - 正则表达式与 ACUTE ACCENT 不匹配
- solidity - 使用 IPFS 以安全的方式铸造 NFT
- karate - 有没有办法用报告(html)文件中的服务器执行时间替换加特林的执行时间?
- text - 带有文本的openlayer标记,关卡有些奇怪
- regression - i 之间有区别吗?并吸收stata?