Nodemailer got error: 'ECONNRESET' Code:'ESOCKET'

荒凉一梦 提交于 2020-02-25 06:20:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!