2
votes

I've successfully connected to a mailbox with node-imap:

const imap = new Imap({
    user: '[email protected]',
    password: 'pwd',
    host: 'imap.yandex.com',
    port: 993,
    tls: true
});

imap.once('ready', () => {
    console.log('Opening inbox');
    imap.openBox('INBOX', true, (error, mailbox) => {
        if (error) throw error;

        // ???

    });
});

How would I now get notified of new emails when they arrive? I've read up about IMAP and I should be using the IDLE command. But how would I achieve this with node-imap?

https://github.com/mscdex/node-imap

1
@ChrisWhite - yes it is! If you had any desire to pose that as an answer I'd love to give it the green tick. - Kong

1 Answers

4
votes

After going through the documentation, it seems that the IMAP connection emits a mail event upon receiving new mail: https://github.com/mscdex/node-imap#connection-events, so listening for that event should be notification that there is new mail to be received or processed.