Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up nodemailer for SMTP

I used this setup to send a mail:

import NodeMailer from 'nodemailer'
import SmtpTransport from 'nodemailer-smtp-transport'

const transporter = NodeMailer.createTransport(SmtpTransport({
  host: 'smtp.1blu.de',
  port: 25,
  debug: true,
  auth: {
    user: '...',
    pass: '...'
  }
}))

transporter.sendMail(options, (error, data) => ...)

But I get this error:

Error: connect ECONNREFUSED 127.0.0.1:25
at Object.exports._errnoException (util.js:749:11)
at exports._exceptionWithHostPort (util.js:772:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1009:14)

Seems like it ignores the host, but why?

like image 371
K.. Avatar asked Oct 24 '25 06:10

K..


1 Answers

I had the very same problem as you and I am using 1blu as well. The issue is related to the TLS library of Node. The following configuration did the job for me.

Here:

var smtpTransport = nodemailer.createTransport("SMTP",{
    host: 'smtp.1blu.de',
    secureConnection: true,
    port: 465,
    auth: {
       user: '...',
       pass: '...'
    },
    tls:{
        secureProtocol: "TLSv1_method"
    }
});
console.log('SMTP Configured');
like image 198
Marvin Avatar answered Oct 26 '25 19:10

Marvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!