When I try to retrieve emails through imap with the code below(using an async function), I get the following console output/error:
Inbox: undefined
/Users/mainuser/node_modules/imap/lib/Connection.js:432 cb(err, self._box); ^ TypeError: cb is not a function
var Imap = require('imap');
var inspect = require('util').inspect;
var imap = new Imap({
user: 'mymailname@mail.com',
password: 'mymailpassword',
host: 'imap.mail.com',
port: 993,
tls: true
});
const openInbox = async () => {
try {
const inbox = await imap.openBox('INBOX', true)
return inbox
}catch(error){
console.log("Error: "+ error)
}
}
imap.once('ready', () => {
console.log('ready')
openInbox()
.then(inbox => console.log('Inbox: ' + inbox))
});
imap.connect()
However, I can open the inbox and output the inbox Object using nested callbacks as shown below:
imap.once('ready', () => {
imap.openBox('INBOX', true, (err, inbox) => {
console.log('Inbox: ' + inbox)
});
});
imap.connect()