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

123
Visualizações
Undefined in console

I try to make seperate function for nodemailer and expecting boolean true or false in return.But when the mail is send to user I'm getting the mail in account but after that instead of true or false in return I'm getting value as undefined.

function nodeMailer(mailOptions){

 var transporter = nodemailer.createTransport({
        service: 'gmail',
        auth: {
            user: get.username,
            pass: get.password
        },
        tls: {
            rejectUnauthorized : false
        }
    });


    transporter.sendMail(mailOptions, (error, info) => {
       if(error) return false;

       return true;
    });
}
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You are getting undefined, because true or false should return your nodeMailer function and not transporter.sendMail. In this case you can create Promise which can help you with that.

var nodeMailer = function(mailOptions) {
    return new Promise(function(resolve, reject){
        var transporter = nodemailer.createTransport({
            service: 'gmail',
            auth: {
                user: get.username,
                pass: get.password
            },
            tls: {
                rejectUnauthorized : false
            }
        });


        transporter.sendMail(mailOptions, (error, info) => {
           if(error) reject(error);

           resolve(info);
        });
       }
   });
}

and then call your promise like below

nodeMailer(yourOptions).then(function(result) {
    // handle success result here
    return info; 
})
.catch(function(err) {
     // handle your error here
})

more about promises you can read here. They are very useful when you need to control your async flow.

about 4 years ago · Santiago Trujillo Relatório

0

Try this by using callback or promise.

about 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