gpt4 book ai didi

javascript - Firebase功能上的"Error: Client network socket disconnected before secure TLS connection was established"

转载 作者:行者123 更新时间:2023-12-05 00:55:16 24 4
gpt4 key购买 nike

我在我的 React.js 项目中使用 nodemailer 和我的 Firebase 函数(服务器端函数)并且收到错误:错误:客户端网络套接字在安全 TLS 连接之前断开连接已建立... 并导致 一些 电子邮件无法发送出去。这对这个项目来说是一个大问题,因为客户端不能丢失从系统发送的电子邮件。为什么会出现此错误,我该如何解决?

Firebase 函数 index.js:

"use strict";
import functions = require('firebase-functions');
import admin = require("firebase-admin");
import nodemailer = require('nodemailer');
import { DocumentSnapshot } from 'firebase-functions/lib/providers/firestore';
import { Change, EventContext } from 'firebase-functions';
import { Status } from './common';

admin.initializeApp(functions.config().firebase);

export const onUserCreated = functions.firestore.document('users/{userId}')
.onCreate(async (snap: { data: () => any; }) => {
console.log("Client create heard! Starting inner...")
const newValue = snap.data();

try {
console.log("Started try{}...")

// Template it
const htmlEmail =
`
<div>
<h2>client Sign Up</h2>
`
// Config it
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: functions.config().email.user,
pass: functions.config().email.password
}
})
console.log("transporter = " + transporter)

// Pack it
const mailOptions = {
from: `email123@gmail.com`,
to: 'email123@gmail.com',
replyTo: `${newValue.email}`,
subject: `user sign up`,
text: `A new user sign up with the email of ${newValue.email}.`,
html: htmlEmail
}

// Send it
transporter.sendMail(mailOptions, (err: any) => {
if(err) {
console.error(err);
} else {
console.log("Successfully sent mail with sendMail()!");
}
})
} catch (error) {
console.error(error)
}
});

函数包.json:

{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"@types/nodemailer": "^6.4.0",
"firebase-admin": "^9.4.1",
"firebase-functions": "^3.11.0",
"nodemailer": "^6.4.16"
},
"devDependencies": {
"firebase-functions-test": "^0.2.3",
"tslint": "^5.12.0",
"typescript": "^3.8.0"
},
"private": true
}

完全错误: enter image description here

最佳答案

在我的情况下,将 TLS 版本添加到 nodemailer 选项后错误消失了:

let transporter = nodemailer.createTransport({
host: 'smtp-server',
port: 25,
tls: {
ciphers : 'SSLv3',
},
});

关于javascript - Firebase功能上的"Error: Client network socket disconnected before secure TLS connection was established",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64885483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com