我正在使用node-imap库读取邮件,邮件事件在初始化后第二次没有被触发。
下面是我的代码
此外,它给出的错误:阅读ECONNRESET作为错误后,第一次检索的电子邮件。
预期邮件(‘imap.once’,函数(x) {}应在邮箱中出现任何新邮件时调用。
Imap.once(‘邮件’,函数(x) {}未被触发。
此事件仅在我运行node.js文件时触发一次,以后不再触发。请给我建议。
imap.connect();
imap.once('ready', function () {
console.log("Imap ready");
readMail();
});
function readMail() {
openInbox(function (err, box) {
imap.once('mail', function (x) {
console.log("New Mail...", x);
executeMail(err);
});
});
}
}根据评论在下面进行了尝试,但仍然不起作用。
function readMail() {
openInbox(function (err, box) {
imap.once('mail', function (x) {
console.log("New Mail...", x);
executeMail(err);
imap.connect();
});
});
}
}发布于 2019-07-08 13:34:38
我想你应该使用imap.on而不是imap.once
imap.on("mail", mail => {
console.log("New mail arrived 1");
});上面的代码对我来说很有效。
https://stackoverflow.com/questions/54644263
复制相似问题