gpt4 book ai didi

node.js - 我正在使用 IMAP npm 库来获取邮件,上面写着 "invalid credentials"

转载 作者:行者123 更新时间:2023-12-04 17:36:36 24 4
gpt4 key购买 nike

我正在使用 IMAP 库从 gmail 中获取电子邮件。我从 Read email body with node js imap 得到引用和 https://www.npmjs.com/package/imap .

我的实现如下:

    var Imap = require('imap'),
inspect = require('util').inspect;

var imap = new Imap({
user: 'xxx@gmail.com',
password: 'xxxxxx',
host: 'imap.gmail.com',
port: 993,
tls: true
});

function openInbox(cb) {
imap.openBox('INBOX', true, cb);
}

imap.once('ready', function() {
openInbox(function(err, box) {
if (err) throw err;
var f = imap.seq.fetch('1:3', {
bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
struct: true
});
f.on('message', function(msg, seqno) {
console.log('Message #%d', seqno);
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
var buffer = '';
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
});
stream.once('end', function() {
console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
});
});
msg.once('attributes', function(attrs) {
console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
});
msg.once('end', function() {
console.log(prefix + 'Finished');
});
});
f.once('error', function(err) {
console.log('Fetch error: ' + err);
});
f.once('end', function() {
console.log('Done fetching all messages!');
imap.end();
});
});
});

imap.once('error', function(err) {
console.log(err);
});

imap.once('end', function() {
console.log('Connection ended');
});

imap.connect();

注意:用户名/密码正确,我在我的 gmail 帐户中启用了 IMAP/POP,但我仍然收到以下错误:

    { Error: Invalid credentials (Failure)
at Connection._resTagged (xxx/server/node_modules/imap/lib/Connection.js:1502:11)
at Parser.<anonymous> (xxx/server/node_modules/imap/lib/Connection.js:194:10)
at Parser.emit (events.js:193:13)
at Parser._resTagged (xxx/server/node_modules/imap/lib/Parser.js:175:10)
at Parser._parse (xxx/server/node_modules/imap/lib/Parser.js:139:16)
at Parser._tryread (xxx/server/node_modules/imap/lib/Parser.js:82:15)
at TLSSocket.Parser._cbReadable (xxx/server/node_modules/imap/lib/Parser.js:53:12)
at TLSSocket.emit (events.js:193:13)
at emitReadable_ (_stream_readable.js:550:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
type: 'no',
textCode: 'AUTHENTICATIONFAILED',
source: 'authentication' }
Connection ended

最佳答案

注意:如果使用 Gmail 帐户,您需要设置 oAuth:

  1. 详细生成访问 token 和获取过程 here .

关于node.js - 我正在使用 IMAP npm 库来获取邮件,上面写着 "invalid credentials",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56475264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com