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

177
Views
Nodemailer email posting but says pending

I'm trying to use Nodemailer in a React/Express app I'm working on and on the server it says it's posting but in the network tab its showing pending and then it never goes through? Here's my code:

const express = require('express');
const router = express.Router();
const nodemailer = require('nodemailer');
require("dotenv").config();
// router.get('/', () => {
// resizeBy.send('Welcome to my email form')
// });
module.exports = () => {
  router.post('/', (req, res) => {
    console.log("inside event handler")
    let transporter = nodemailer.createTransport({
      service: 'Gmail',
      port: 465,
      auth: {
        user: process.env.EMAIL,
        pass: process.env.PASSWORD
      }
    });
    let mailOptions = {
      from: process.env.EMAIL,
      to: `${req.body.values.email}`,
      subject: `Message from: ${process.env.EMAIL}`,
      html: `
    <h3>Information</h3>
    <ul>
    <li>Name: ${req.body.values.name}</li>
    <li>Email: ${req.body.values.email}</li>
    </ul>
  
    <h3>Message</h3>
    <p>${req.body.values.message}</p>
    `
    }
    transporter.sendMail(mailOptions, (err, response) => {
      if (err) {
        res.send(err)
        console.log("Error happened in send email", err)
      } else {
        res.send('Success! Message sent!')
        console.log("Message sent")
      }
    })
    transporter.close();


  })

  return router;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like you don't need to use transporter.close() since you aren't pooling connections. Using it in this context is probably your problem.

transporter.sendMail() is async so you are sending mail and then immediately closing it with transporter.close(). This means the sendMail callback isn't fired, which in turn means res.send() is never sent, which results in your never ending and pending http request to your client.

I suggest removing the transporter.close() line and retrying.

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!