问题
I tried to send mail using Nodemailer by using my mail server. It work fine in localhost:8000 buy when I deploy my project to production mode It's got error: 'ECONNRESET'
fyi: I use express for the backend and deploy this project on window server 2012
This is an error
error cannot sendmail: Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:201:27) {
errno: 'ECONNRESET',
code: 'ESOCKET',
syscall: 'read',
command: 'CONN'
Here is the code
const nodemailer = require('nodemailer')
let transporter = nodemailer.createTransport({
host: 'mailserver',
port: port,
tls: {
rejectUnauthorized: false
},
}
)
function Emailsender(email, link) {
let mailOption = {
from: 'xxxxxxxx@company.org',
to: `${email}`,
subject: 'News',
text: link
}
transporter.sendMail(mailOption, function (err, data) {
if (err) {
console.log('error cannot sendmail:', err)
}
else {
console.log('Email has been send')
}
})
}
来源:https://stackoverflow.com/questions/59297141/nodemailer-got-error-econnreset-codeesocket