nodejs中nodemailer报错: 链接超时 510 connect ETIMEDOUT 127.0.0.1:456(已解决)

//cmd打印的错误
Error: connect ETIMEDOUT 127.0.0.1:456 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) { errno: 'ETIMEDOUT', code: 'ESOCKET', syscall: 'connect', address: '127.0.0.1', port: 456, command: 'CONN' }

我的代码

'use strict'
const nodemailer = require('nodemailer');

//创建邮件发布对象
let transporter = nodemailer.createTransport({
    host: 'smtp.qq.com',
    port: 456,
    secure: true,
    auth:{
        user:'a_ananiah@foxmail.com',
        pass:'muzshiiihtjfeadi'
    }
});

function send(maill,code){
    // 邮件信息
    let mailObj = {
        form: '"Fred Foo" <a_ananiah@foxmail.com>',
        to: maill,
        subject: "1902",
        text: `您的验证码是${code},有效期是五分钟!`
    }
    //发送邮件 
    transporter.sendMail(mailObj,(err,data) => {
        console.log(err)
        console.log(data)
    })
}

错误原因:变量名大写的原因。变量名称改成小写就OK

let mailobj = { //此处变量名称改成小写就OK
        form: '"Fred Foo" <a_ananiah@foxmail.com>',
        to: maill,
        subject: "1902",
        text: `您的验证码是${code},有效期是五分钟!`
    }
    //发送邮件 
    transporter.sendMail(mailobj,(err,data) => { //此处变量名称改成小写就OK
        console.log(err)
        console.log(data)
    })

PS:原谅Ananiah是个小白,各位谅解!

posted @ 2019-11-20 17:45  Ananiah  阅读(1808)  评论(0编辑  收藏  举报