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

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

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 Report

0

Try this by using callback or promise.

about 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!