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

183
Visualizações
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 Respostas
Responde à pergunta

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