Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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], ...);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda