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

366
Views
Nodemailer is not sending e-mail, but no errors occur

I am currently making a sign-up confirmation email function for my website, and I have done something like it before. Only this time I am running into a problem; The emails aren't sending, while the package returns no error.

I took the code out of context and let it e-mail me as soon as it launches, and even then it doesn't work (while saying it does)

My code (out of context one):

const nodemailer = require('nodemailer')

const mailTransporter = nodemailer.createTransport({
    host: `smtp.gmail.com`,
    port: 465,
    secure: true,
    auth: {
        "user": "<theemail>@gmail.com",
        "pass": "<thekey>"
    }
})

mailTransporter.sendMail({
    from: `<the-email>@gmail.com`,
    to: `<myemail>@gmail.com`,
    subject: `some subject`,
    text: `some text`
}, (err, data) => {

    if (err)
        console.log(err)
    else
        console.log(`success`)

})

When this code is run, success is logged in the console.

Before replying, keep in mind that I already am:

  • using the google 16-character password.
  • using real values, just replaced them for privacy reasons.

EDIT: Code works when put at the end of my main file (index.js):

const nodemailer = require('nodemailer')

const mailTransporter = nodemailer.createTransport({
    host: `smtp.gmail.com`,
    port: 465,
    secure: true,
    auth: {
        user: "<email>@gmail.com",
        pass: "<pass>"
    }
})

mailTransporter.sendMail({
    from: `<sendemail>@gmail.com`,
    to: `<myemail>@gmail.com`,
    subject: `some subject`,
    text: `some text`
}, (err, data) => {

    if (err)
        console.log(err)
    else
        console.log(`success`)

})

However, the code does not work inside my module (the 'set' parameter is logged, but nothing further happens, my process then also seems to stop running, express stops replying to requests):

module.exports = (set) => {

    let success = undefined

    console.log(set)

    const mt = nodemailer.createTransport({
        host: `smtp.gmail.com`,
        port: 465,
        secure: true,
        auth: {
            user: "<email>@gmail.com",
            pass: "<pass>"
        }
    })
    
    mt.sendMail({
        from: `<sendemail>@gmail.com`,
        to: `<myemail@gmail.com`,
        subject: `some subject`,
        text: `some text`
    }, (err, data) => {
    
        if (err)
            console.log(err)
        else
            console.log(`success`)
    
    })

    

    while (success == undefined) {}

    return success

}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Ad i understand your problem ,I see a never ending while loop there maybe that causes the problem so if you need something to happen in success like res.sendStatus(200) (since you have mentioned express ) just pass a 'callback' function to your funtion like this:

module.exports = (set,callback) => {

    let success = undefined

    console.log(set)

    const mt = nodemailer.createTransport({
        host: `smtp.gmail.com`,
        port: 465,
        secure: true,
        auth: {
            user: "<email>@gmail.com",
            pass: "<pass>"
        }
    })
    
    mt.sendMail({
        from: `<sendemail>@gmail.com`,
        to: `<myemail@gmail.com`,
        subject: `some subject`,
        text: `some text`
    }, callback)

}

And in your router:

router.post("sendEmail",(req,res)=>{
send(yourset,(err, data) => {
        if (err)
            console.log(err)
            res.sendStatus(500)
        else{
            console.log(`success`)
            res.sendStatus(200)
           }
    }}
})
about 4 years ago · Juan Pablo Isaza Report

0

You can also try this method to create Transport for Gmail

transport = nodemailer.createTransport({
                    service: 'Gmail',
                    auth: {
                        user: setting.mailService.user,
                        pass: setting.mailService.pass,
                    }
                })

And I think your email has gone to the spam folder according to Google rules.

If the messages are not in the spam folder, you may need to lower your Gmail security settings.

https://nodemailer.com/usage/using-gmail/

https://www.google.com/settings/security/lesssecureapps

about 4 years ago · Juan Pablo Isaza Report

0

It appears that the email was simply not working when it was inside of an exported function (module.exports = () => {}), when I put it directly in the file instead of requiring and calling it as external function, it worked.

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