我正在尝试使用节点imap模块访问我的Gmail。
我尝试了如下的mail-listener2的基本示例。我用我的gmail地址,密码和imap.gmail.com替换为host.However,我面临以下错误消息。
{[错误:请通过网络浏览器登录: https://support.google.com/mail/accounts/answer/78754(失败)] textCode:' ALERT',来源:'身份验证' } imapDisconnected
我检查了我的Gmail设置,启用了低安全应用程序。启用IMAP并验证我的凭据是否正确。有人能告诉我我错过了什么,我在哪里出错了。我尝试了其他node-imap模块,如npm-imap和imap-simple。
var MailListener = require("mail-listener2");
var mailListener = new MailListener({
username: "imap-username",
password: "imap-password",
host: "imap-host",
port: 993, // imap port
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
markSeen: true, // all fetched email willbe marked as seen and not fetched next time
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
attachments: true, // download attachments as they are encountered to the project directory
attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
});
mailListener.start(); // start listening
// stop listening
//mailListener.stop();
mailListener.on("server:connected", function(){
console.log("imapConnected");
});
mailListener.on("server:disconnected", function(){
console.log("imapDisconnected");
});
mailListener.on("error", function(err){
console.log(err);
});
mailListener.on("mail", function(mail, seqno, attributes){
// do something with mail object including attachments
console.log("emailParsed", mail);
// mail processing code goes here
});
mailListener.on("attachment", function(attachment){
console.log(attachment.path);
});
答案 0 :(得分:1)
我遇到了同样的问题,作为快速修复,您可以启用对“安全性较低的应用”的访问权限,请访问:
https://support.google.com/accounts/answer/6010255
此外,您可以生成应用程序密码,但我认为您必须激活双因素身份验证(我不是很确定)。 希望它有所帮助。