Open Menter32 opened 5 years ago
I want to check for new emails and parse them every X seconds in Gmail.
To keep it connected all the time I have this:
var imap = new IMap(Config.Email); imap.connect(); imap.on("ready", () => { imap.openBox("INBOX", false, (Error, mailBox) => { if (Error) { console.error(`IMap opening inbox: ${Error}`); return imap.end(); } }); }); imap.on("error", (Error) => { console.error(`IMap connection: ${Error}`); imap.connect(); }); imap.on("end", () => { console.error(`IMap connection ended`); imap.connect(); });
And for searching for email I use "forever" function from async library. It executes this function:
function Search(IMap, Callback) { try { if(IMap.state != 'authenticated') { console.error(`Not authenticated`); return Callback(); } console.log(`Pre-search`); IMap.search(["UNSEEN"], function(Error, Results) { console.log(`Search`); if(Error) { console.error(`IMap searching: ${Error}`); return Callback(); } if(!Results || !Results.length) { console.log(`No emails`); return Callback(); } console.log(`Fetching emails`); ...
It works fine for a couple of hours but when connection randomly ends it seems to be stuck on IMap.search when it should probably be called with Error? IMap reconnects but as checking email function stopped on IMap.search it never called Callback
IMap.search
Error
Callback
28-03 20:58:30.561: Pre-search 28-03 20:58:31.093: IMap connection ended
Would appreciate if I could be told how should it be done correctly. Thanks.
Is there any update? I have the same issue.
I have this problem too,have you solved it now?
I want to check for new emails and parse them every X seconds in Gmail.
To keep it connected all the time I have this:
And for searching for email I use "forever" function from async library. It executes this function:
It works fine for a couple of hours but when connection randomly ends it seems to be stuck on
IMap.search
when it should probably be called withError
? IMap reconnects but as checking email function stopped on IMap.search it never calledCallback
Would appreciate if I could be told how should it be done correctly. Thanks.