const ImapClient = require('emailjs-imap-client').default;
(async () => {
// Initialize imap client
const client = new ImapClient('imap.mail.ru', 993, {
logLevel: 1000,
auth: {
user: '',
pass: ''
}
});
// Handling imap mail error
client.onerror = (err) => {
throw new Error(`Error IMAP handling: ${err}`);
};
// Create mail connection
await client.connect();
// Getting messages on mail
const listMessages = await client.listMessages('INBOX', '1:*', ['uid', 'flags', 'envelope', 'body[]']);
for (const message of listMessages) {
const messageDate = new Date(message.envelope.date);
const messageSubject = message.envelope.subject;
const messageBody = message['body[]'];
console.log(messageSubject);
}
// Close mail connection
await client.close();
})();
client.listMailboxes().then((mailboxes) => { console.warn(mailboxes); })
{ root: true,
children:
[ { name: 'INBOX',
delimiter: '/',
path: 'INBOX',
children: [Array],
flags: [Array],
listed: true },
{ name: 'Нежелательная почта',
delimiter: '/',
path: '&BB0ENQQ2BDUEOwQwBEIENQQ7BEwEPQQwBE8- &BD8EPgRHBEIEMA-',
children: [],
flags: [],
listed: true },
{ name: 'Нужное',
delimiter: '/',
path: '&BB0EQwQ2BD0EPgQ1-',
children: [],
flags: [],
listed: true },
{ name: 'Спам',
delimiter: '/',
path: '&BCEEPwQwBDw-',
children: [],
flags: [Array],
listed: true,
specialUse: '\\Junk' },
{ name: 'Отправленные',
delimiter: '/',
path: '&BB4EQgQ,BEAEMAQyBDsENQQ9BD0ESwQ1-',
children: [],
flags: [Array],
listed: true,
specialUse: '\\Sent',
specialUseFlag: '\\Sent' },
{ name: 'Черновики',
delimiter: '/',
path: '&BCcENQRABD0EPgQyBDgEOgQ4-',
children: [],
flags: [Array],
listed: true,
specialUse: '\\Drafts',
specialUseFlag: '\\Drafts' },
{ name: 'Корзина',
delimiter: '/',
path: '&BBoEPgRABDcEOAQ9BDA-',
children: [],
flags: [Array],
listed: true,
specialUse: '\\Trash',
specialUseFlag: '\\Trash' } ] }