我使用站点contact@monsite.com
的电子邮件帐户将smtp警报消息发送到用户的电子邮件。但这仍然给我这个错误
Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
errno:“ ECONNREFUSED”, 代码:“ ESOCKET”, syscall:“连接”, 地址:“ 127.0.0.1”, 端口:465, 命令:“ CONN” }
这是我的代码
// send mail function
exports.sendMailer = (optionsTransporterMail = OptionsTransporterMail, optionsMail = OptionsMail, callback) => {
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport(optionsTransporterMail);
transporter.sendMail(optionsMail, function (err, info) {
callback(err, info)
});
}
sendMailer({
service: 'mail.mywebsite.com',
port: 465,
secure: true,
auth: {
user: 'contact@mywebsite.com',
pass: '12345678'
}
}, {
from: '"My app <contact@mywebsite.com>',
to: user@domain.com,
subject: "Notify",
text: "Hello worlds",
html: "Hello worlds"
}, (err, info) => {
if err console.log(err);
console.log(info)
})
它仍然给出此错误
Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 465,
command: 'CONN'
}
答案 0 :(得分:1)
我假设您要使用mail.mywebsite.com
来发送电子邮件。用这些术语,您必须在选项中设置host
值,因为默认情况下它似乎使用localhost(127.0.0.1)。
请尝试以下代码:
sendMailer({
host: 'mail.mywebsite.com',
port: 465,
secure: true,
auth: {
user: 'contact@mywebsite.com',
pass: '12345678'
}
}, {
from: '"My app <contact@mywebsite.com>',
to: user@domain.com,
subject: "Notify",
text: "Hello worlds",
html: "Hello worlds"
}, (err, info) => {
if err console.log(err);
console.log(info)
})