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

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Try this by using callback or promise.

about 4 years ago · Santiago Trujillo 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