NodeMailerlogin无效

我是node.js编程的新手。我使用nodemailer模块来发送邮件。

const nodemailer = require ('nodemailer'), credentials=require('./credentials.js'); var mailTransport=nodemailer.createTransport({ service:'Gmail', auth: { user : credentials.gmail.user, pass : credentials.gmail.password, } }); function sendMail(mail_id){ mailTransport.sendMail({ from: ' "my name" <myname@gmail.com>', to : mail_id, //user@gmail.com subject : 'Hello', text: "Hello How do u do ?", },function(err,info){ if(err){ console.log('Unable to send the mail :'+err.message); } else{ console.log('Message response : '+info.response); } }); } exports.sendMail=sendMail; 

这是我发送电子邮件给不同用户的程序。 但我得到无效的login 。 我不知道为什么会这样。 我是新的node.js和服务器端脚本。
我使用我的Gmail用户名和密码的凭据。
请帮帮我。

您是否仔细检查了您的login凭证? 你还仔细检查了你的“来自”地址,以匹配你的电子邮件?

我在3周前使用了nodemailer进行了一些testing,在github页面上给出了gmail的例子,它像一个魅力:

https://github.com/andris9/Nodemailer

无效的login表示错误的/错误的凭据。

一个原因可能是Gmail的“现代安全标准”保护。

请检查您的Gmail收件箱是否有任何新邮件有“Google帐户:login尝试被阻止”

如果是,请打开邮件并点击链接https://www.google.com/settings/security/lesssecureapps

将“访问不太安全的应用程序”设置为“打开”。 再试一次,它应该现在工作。

你需要启用安全的应用程序:

| * | 如果你使用Gmail,

 Use : service: 'gmail', Goto : https://myaccount.google.com/lesssecureapps Enable : Allow less secure apps: ON 

| * | 如果你使用雅虎,

 Use : service: 'yahoo', Goto : https://login.yahoo.com/account/security Enable : Allow apps that use less secure sign in 

| * | 如果你使用Live或Hotmail,不需要启用任何东西。

 Use : service: 'hotmail',