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

351
Visualizações
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
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