0

I'm following along with this guide taking the node.js route for backend - https://blog.mailtrap.io/react-contact-form/. When I go to run my back end I get this error -

$ 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,

Here is what my index.js looks like -

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'
      })
    }
  })
})

Anyone know what could be wrong? Thanks!

Johnny Bravo
  • 163
  • 11
  • Do you have an SMTP mail transfer agent server running on your localhost machine? (If you're not sure what I mean by that, you probably don't.) In your call to `.createTransport()` you need to mention such a server. See this example. https://nodemailer.com/about/#example – O. Jones Apr 06 '20 at 14:21
  • Yeah, the address is correct as I'm running it locally for now. – Johnny Bravo Apr 07 '20 at 02:28
  • Your error message means nothing is listening on localhost port 465. The protocol on that port was deprecated over a decade ago, and maybe your MTA listens on 587 instead. Check this out. https://stackoverflow.com/questions/15796530/what-is-the-difference-between-ports-465-and-587 – O. Jones Apr 07 '20 at 10:50
  • good point, I switched it over to port 587 and still get the same error though. But I'm glad you pointed that out. – Johnny Bravo Apr 07 '20 at 15:15
  • @O.Jones You were so right. I thought that was supposed to link to my front end X.X It's working now thank you :). – Johnny Bravo Apr 10 '20 at 14:47

0 Answers0