nodejs nodemailer 2.x无效

时间:2016-07-06 15:45:12

标签: node.js runtime-error nodemailer

如果我从家里运行例程它可以正常工作但是当我尝试运行相同的例程时我开始工作时它会给我一个错误。见下文:

<Error: getaddringo ENOTFOUND smtp.gmail.com smtp.gmail.com:25
     at errnoException <dns.js:28:10>
     at GetAddrInfoReqWrap.onlookup [as oncomplete] <dns.js:79:26>
   code: 'ENOTFOUND'
   errno: 'ENOTFOUND',
   syscall: 'getaddringo',
   hostname:'smtp.gmail.com',
   host: 'smtp.gmail.com',
   port: 25>

以下是我使用的代码,请参阅以下内容:

// create reusable transporter object using the default SMTP transport
    var transporter = nodemailer.createTransport('smtp://"myemail"%40gmail.com:"mypassword"@smtp.gmail.com');
// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"Foo" <"myemail">', // sender address
    to: 'foo@gmail.com', // list of receivers
    subject: 'Hello', // Subject line
    text: 'Hello world', // plaintext body
    html: '<b>Hello world</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

0 个答案:

没有答案