错误:运行Node.js发送电子邮件时连接ECONNREFUSED

时间:2020-04-06 14:14:58

标签: node.js reactjs express nodemailer

我将遵循本指南,将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'
      })
    }
  })
})

有人知道可能出什么问题吗?谢谢!

0 个答案:

没有答案