NodeMailer无效登录

Sri*_*sha 16 javascript smtp server-side node.js nodemailer

我是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;
Run Code Online (Sandbox Code Playgroud)

这是我向不同用户发送电子邮件的程序.但我得到无效登录.我不知道为什么会这样.我是node.js和服务器端脚本的新手.
我正在使用我的gmail用户名和密码来获取凭据.
请帮我.

小智 29

一个原因可能是Gmail的"现代安全标准"保护.

检查gmail收件箱中是否有任何主题为"Google帐户:登录尝试已被屏蔽"的新邮件

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

将"访问不太安全的应用程序"设置为"打开".再试一次,现在应该可以了.


Suj*_*U N 13

你需要为应用启用安全性:

|*| 如果你使用gmail,

Use :

    service: 'gmail',

Goto : 

    https://myaccount.google.com/lesssecureapps

Enable : 

    Allow less secure apps: ON
Run Code Online (Sandbox Code Playgroud)

|*| 如果你使用雅虎,

Use :

    service: 'yahoo',

Goto : 

    https://login.yahoo.com/account/security

Enable : 

    Allow apps that use less secure sign in
Run Code Online (Sandbox Code Playgroud)

|*| 如果您使用Live或Hotmail,则无需启用任何内容.

Use :

    service: 'hotmail',
Run Code Online (Sandbox Code Playgroud)

  • 讲述了您在过去几年中需要了解的有关 Microsoft 的所有信息 (2认同)

Dan*_*cki 13

特别是 2 个问题:或者您没有启用不太安全的应用程序 https://myaccount.google.com/lesssecureapps或者您没有启用Display Unlock Captcha https://accounts.google.com/DisplayUnlockCaptcha,您需要打开它们两个。


sma*_*t24 9

您是否仔细检查了登录凭据?您是否也仔细检查了您的"来自"地址以匹配您的电子邮件?

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

https://github.com/andris9/Nodemailer

无效登录表示输入错误/错误凭据.


d1f*_*ult 6

就我而言,仅打开不太安全的应用程序是不够的:https://myaccount.google.com/lesssecureapps

我还必须启用显示解锁验证码: https: //accounts.google.com/DisplayUnlockCaptcha

这解决了我的问题,我能够使用 nodemail 和 gmail 发送电子邮件。

实际上,这件事不是随机的,nodemailer 社区网站本身表示,如果打开不太安全的应用程序无法单独工作,则执行第二步以启用验证码。
https://community.nodemailer.com/using-gmail/

在此输入图像描述

上图取自我分享的nodemailer文章链接。