Error: connect ECONNREFUSED 127.0.0.1:465 nodemailer

后端 未结 4 890
礼貌的吻别
礼貌的吻别 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)
           }
    

提交回复
热议问题