Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!