邮件服务器验证失败"/>
使用MailListener连接邮件服务器验证失败
我正在尝试使用 Node.js 中的 MailListener 库连接到电子邮件服务器并收听传入的电子邮件。但是,我遇到了身份验证失败问题,即使凭据确实有效。这是我正在使用的代码:
const MailListener = require("mail-listener5");
const axios = require("axios");
const arguments = process.argv.slice(2);
var user = arguments[0];
var pass = arguments[1];
if (user.includes("@gmail")) {
var imap = "imap.gmail";
user = user.replace("@gmail", "");
} else if (user.includes("@outlook")) {
var imap = "imap-mail.outlook";
user = user.replace("@outlook", "");
} else {
console.log(" * ERROR message: Invalid email address");
}
console.log(user, pass, imap);
const Listener = new MailListener({
username: user,
password: pass,
host: imap,
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX",
searchFilter: [["FROM", "[email protected]"], ["SUBJECT", "New Steam Account Email Verification"], ["UNSEEN"]],
markSeen: true,
fetchUnreadOnStart: true,
});
Listener.on("mail", async (mail, seqno, attributes) => {
const regex = /https:\/\/store\.steampowered\\/account\/newaccountverification\?stoken=[^&]+&creationid=[^"]+/;
const match = regex.exec(mail.html);
if (match) {
const verificationLink = match[0];
try {
const response = await axios.get(verificationLink);
console.log(" * INFO message: Verification link visited successfully:", verificationLink);
} catch (error) {
console.error(" * ERROR message: Error visiting the verification link:", error.message);
}
} else {
console.log(" * ERROR message: Verification link not found in the email");
}
});
Listener.on("error", (err) => {
console.log(" * ERROR message: ", err);
});
Listener.start();
当我运行这段代码时,出现以下错误:
ERROR message: Error: Invalid credentials (Failure)
at Connection._resTagged (C:\Users\maxar\node_modules\imap\lib\Connection.js:1502:11)
at Parser.<anonymous> (C:\Users\maxar\node_modules\imap\lib\Connection.js:194:10)
at Parser.emit (node:events:513:28)
at Parser._resTagged (C:\Users\maxar\node_modules\imap\lib\Parser.js:175:10)
at Parser._parse (C:\Users\maxar\node_modules\imap\lib\Parser.js:139:16)
at Parser._tryread (C:\Users\maxar\node_modules\imap\lib\Parser.js:82:15)
at Parser._cbReadable (C:\Users\maxar\node_modules\imap\lib\Parser.js:53:12)
at TLSSocket.emit (node:events:513:28)
at emitReadable_ (node:internal/streams/readable:590:12)
at process.processTicksAndRejections (node:internal/process/task_queues:81:21) {
type: 'no',
textCode: 'AUTHENTICATIONFAILED',
source: 'authentication'
}
我不知道是什么导致了这个问题,也许是缺少应用程序密码或 OAuth 问题,我不知道。
我试过:
- 遍历堆栈溢出
- 问AI
- 将库从 mail-listener2 更改为 mail-listener5
- 检查文档
更多推荐
使用MailListener连接邮件服务器验证失败
发布评论