Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

414
Visualizações
How to get data of new mail message in node-imap

I need to get information of new mail message in new mail message event. Specifically:

  • E-mail address which sended mail
  • Message title
  • Message content (text)

My code at this moment:

let Imap = require('node-imap')

let imap = new Imap({
    user: '***@gmail.com',
    password: '***',
    host: 'imap.gmail.com',
    port: 993,
    tls: true
});
imap.on('ready', () => {
    imap.openBox('INBOX', true, (err, box) => {
        if (err) console.log(err)
        else console.log('Recipient is ready for accepting')
    })
})
imap.on('mail', mail => {
    const title = ?
    const subject = ?
    const email = ?
    console.log(`Email author: ${email} Title: ${title}, Description: ${subject}`)
})

imap.connect()
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

imap.on('mail', ...) did not provide informations of new mails. Only a number of new mails.

mail(< integer >numNewMsgs) - Emitted when new mail arrives in the currently open mailbox.

To get the mail data use imap.seq.fetch or imap.search. You can find some examples here: https://github.com/mscdex/node-imap#connection-events

Maybe this helps (https://github.com/mscdex/node-imap/issues/359#issuecomment-37099842):

imap.search([ 'NEW' ], function(err, results) {
   if (err || !results.length) return imap.end();

   // fetch all resulting messages
   imap.fetch(results, ....);
   // or just fetch only the first result... which may not necessarily be newest
   // because the server can return results in any order
   imap.fetch(results[0], ...);
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda