我正在使用imapflow這樣的包:
import config from './config.js';
import { ImapFlow } from 'imapflow';
const client = new ImapFlow({
host: 'imap.gmail.com',
port: 993,
secure: true,
auth: {
user: '[email protected]',
pass: '123'
}
});
await client.connect();
console.log('OK');
它與Invalid credentials (Failure). 我已經四次檢查登錄名和密碼是否正確,在 GMail 設定中啟用了 IMAP。雖然沒有啟用不安全的應用程式,但我更愿意保持這種狀態。當我嘗試在 Thunderbird 中使用相同的憑據時,它會打開一個 OAuth 登錄視窗,我想我應該以某種方式將其與 imapflow 合并?還是有不同的解決方案?
uj5u.com熱心網友回復:
Gmail 不允許使用普通用戶名和密碼訪問其 IMAP 服務。您應該首先通過 Gmail api 示例(此處)獲取 OAuth2.0 憑據,然后將其轉換為 xoauth2。
let {installed: {client_id, client_secret}} = require('./client_secret') // the client_secret.json file
let xoauth2gen = xoauth2.createXOAuth2Generator({
user: '*******', // the email address
clientId: client_id,
clientSecret: client_secret,
refreshToken: refresh_token
})
xoauth2gen.getToken(function(err, xoauth2token) {
if (err) {
return console.log(err)
}
let imap = new Imap({
xoauth2: xoauth2token,
host: 'imap.gmail.com',
port: 993,
tls: true,
authTimeout: 10000,
debug: console.log,
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/461879.html
