node.js - 错误:运行 Node.js 以发送电子邮件时连接 ECONNREFUSED
问题描述
我正在遵循本指南,将 node.js 路由用于后端 - https://blog.mailtrap.io/react-contact-form/。当我去运行我的后端时,我得到了这个错误 -
$ node index.js
{ Error: connect ECONNREFUSED 23.217.138.109:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '23.217.138.109',
port: 465,
这是我的 index.js 的样子 -
var transport = {
host: 'http://localhost:3000/',
port: 465,
secure: true,
auth: {
user: creds.USER,
pass: creds.PASS
}
}
var transporter = nodemailer.createTransport(transport)
transporter.verify((error, success) => {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take messages');
}
});
router.post('/send', (req, res, next) => {
var name = req.body.name
var email = req.body.email
var message = req.body.message
var content = `name: ${name} \n email: ${email} \n message: ${message} `
var mail = {
from: name,
to: 'myEmail@yahoo.com',
subject: 'New Message from Contact Form',
text: content
}
transporter.sendMail(mail, (err, data) => {
if (err) {
res.json({
status: 'fail'
})
} else {
res.json({
status: 'success'
})
}
})
})
有谁知道可能出了什么问题?谢谢!
解决方案
推荐阅读
- python - 使用 python 套接字的 FIN/ACK 通知
- reactjs - 如何使用socket.io在本机反应中为Web基础应用程序创建与后端服务器的聊天连接?
- python - Python:尽管明显存在,但看不到功能
- vb.net - 是否可以在未安装引擎的情况下使用 ADODB/OleDB 连接?
- ruby-on-rails - 如何在变量中添加数组并通过get方法将其发送到url
- excel - 过滤列表范围内的唯一值
- c# - 当我使用参数化查询时出现此错误(必须声明标量变量@“regNo”)
- java - 尝试通过android调用JSON api时出现无效请求错误
- android - 适用于 Ios 和 Android 的一种 URL 方案
- javascript - React Native:使用 FlatList 和 DatePicker 创建时间列表