Error: connect ECONNREFUSED 127.0.0.1:465 nodemailer

后端 未结 4 889
礼貌的吻别
礼貌的吻别 2021-01-17 14:50

I was using my gmail account to send an smtp alert messages to my users email . Example, registration or account blocked etc. I am using a nodemailer and was email were sent

相关标签:
4条回答
  • 2021-01-17 15:16

    I have faced the same error, this worked for me

    try {
                var transporter = nodemailer.createTransport({
                    service: 'gmail',
                    port:465,
                    secure: true, // true for 465, false for other ports
                    logger: true,
                    debug: true,
                    secureConnection: false,
                    auth: {
                        user: 'test@gmail.com', // generated ethereal user
                        pass: '*****', // generated ethereal password
                    },
                    tls:{
                        rejectUnAuthorized:true
                    }
                })
    
             var info = await transporter.sendMail({
                    from: 'myuser@outlook.com', // sender address
                    to: 'anotheruser@hotmail.co.uk', // list of receivers
                    subject: 'Test Email', // Subject line
                    text: 'Hello world ?' // plain text body
                    html: output, // html body
            });
            }
           catch(error) {
                    console.log(error)
           }
    
    0 讨论(0)
  • 2021-01-17 15:21

    Thank you for your time guys. Below is what works for me .

    nodemailer.createTransport('smtps://user%myDomain.com:pass@smtp.gmail.com');
    

    changed to

    var smtpConfig = {
        host: 'smtp.gmail.com',
        port: 465,
        secure: true, // use SSL
        auth: {
            user: 'user@myDomain.com',
            pass: 'pass@pass'
        }
    };
    var transporter = nodemailer.createTransport(smtpConfig);
    

    I Found the example above on the doc https://github.com/nodemailer/nodemailer . I am suspecting this may happened to you if your password contained @ symbol considering u and the smtps link. Its therefore advisable to split it into an object without the @ symbol interfering with your smtps url. This is my guess thought. Nonetheless the above solution works for me. Plus don't forget to allow less secure apps from your google console.

    0 讨论(0)
  • 2021-01-17 15:41

    Adding a config for Bluehost for anyone using it.

    let transporter = nodemailer.createTransport({
        host: 'box1109.bluehost.com',
        port: 465,
        secure: true,
        auth: {
            user: 'someusername@somewebsite.com',
            pass: 'yourpassword'
        }
    });
    

    You can verify the options using the verify() method.

    transporter.verify((err, success) => {
        if (err) console.error(err);
        console.log('Your config is correct');
    });
    

    If you are experiencing this error, make sure that the host property is set properly.

    console.log(transporter.options.host);
    

    I spent 20 minutes on this error to find out that the host property was undefined (I was using an environment variable to port it into the config).

    0 讨论(0)
  • 2021-01-17 15:42

    I was using secure: false and I faced the same issue on production and below was the solution that worked for me:

    const transporter = nodemailer.createTransport({
      host: <hostname>,
      port: 25,
      secure: false,
      logger: true,
      debug: true,
      ignoreTLS: true // add this 
    });
    

    Hope this will help someone.

    0 讨论(0)
提交回复
热议问题