3

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

const imap = new Imap({
    user: 'user@yandex.com',
    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

Kong
  • 8,792
  • 15
  • 68
  • 98

1 Answers1

6

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.

Chris White
  • 1,068
  • 6
  • 11