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

356
Views
imap-simple giving an error when trying to move an email from Inbox to Trash or Drafts ... By node.js

I have started a new email project. It's very challenging to me because first time I am working with own custom email project. I am using node.js for creating REST full API. Using imap-simple module for accessing Internet message access. Everything is working like send email, receive email, add flag etc from our own server. But problem is when trying to move an email from Inbox to Drafts folder it's giving an error. Can you please see my code snippet below and guide me for the right way.

const imaps = require('imap-simple');

module.exports.moveEmail = async (req, res)=>{
  let user  = req.body;
  let UID = req.params.uid
  try{
    const connection = await imaps.connect({
      imap: {
        user: user.user, // User email
        password: user.password, // User email password
        host: 'server.XXXX.com',
        port: XXXX,
        authTimeout: 10000,
        tls: true,
        tlsOptions: { rejectUnauthorized: false },
      },
    });
    await connection.openBox('INBOX')
    const searchCriteria = [['UID', UID], ['TO', user.user]]
    const fetchOptions = {
      bodies: ['HEADER', ''], // Empty string means full body
      markSeen: false
    }
    const messages = await connection.search(searchCriteria, fetchOptions)
    if (messages.length === 0) {
      return res.send({message:`ID ${UID} Email not found`})
    }
    // console.log(messages)
    connection.moveMessage(UID, 'Drafts', (err) => {
      if (err){
          console.log(err)
          console.log({status:500, message:'Problem marking email move to Drafts'});
          rej(err);
      }else{
        connection.end();
        return res.send({status:200, message:`Email flag removed successfully!`})
      }
    })

  }catch (error){
    console.log(error)
  }
}

Hope fully some one have a nice solution.

enter image description here

about 4 years ago · Juan Pablo Isaza
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!