D
D
DefaultX2019-05-10 12:42:50
Email
DefaultX, 2019-05-10 12:42:50

How to get mail.ru mailings in IMAP?

Welcome all.
I'm trying to receive emails from mail.ru using the imap protocol (either - emailjs-imap-client), emails are received only from the inbox, but if the email is included in the mailing list, then this email is not returned.
Code example

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();
})();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akelsey, 2019-05-10
@DefaultX

Well, not being a programmer, I see that you receive items only from the inbox:
Probably you need to rewrite the code so that it recursively bypasses all folders.

V
Vladimir Proskurin, 2019-05-10
@Vlad_IT

As akelsey correctly noted above, you receive mail only from the INBOX box, in order to receive mail from all boxes, you need to get all these boxes, and row letters for them separately.
This is how I got the list of boxes
and got this answer

List of boxes
{ 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' } ] }

There are a lot of interesting things. You also need the path parameter, and you must substitute it instead of INBOX.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question