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

264
Vistas
nodemailer: Connection closed unexpectedly

I deployed a function to firebase and when I test the function to send an email I get the following error:

Error: Connection closed unexpectedly
    at SMTPConnection._onClose (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:824:34)
    at TLSSocket.SMTPConnection._onSocketClose (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:191:42)
    at Object.onceWrapper (events.js:520:26)
    at TLSSocket.emit (events.js:412:35)
    at TLSSocket.emit (domain.js:537:15)
    at net.js:686:12
    at TCP.done (_tls_wrap.js:564:7)
    at TCP.callbackTrampoline (internal/async_hooks.js:130:17) 

This is the function I use to send the email:

const transporter = nodemailer.createTransport({
  host: "host",
  port: 465,
  secure: true,
  auth: {
    user: "email",
    pass: "pass",
  },
});

exports.sendMailUser =
  functions.firestore.document("collection/Users").onUpdate(async (snapshot, context) => {
    const data = snapshot.after.data();
    const dataReceived = data.users;
    const name = dataReceived[dataReceived.length - 1].name;
    const email = dataReceived[dataReceived.length - 1].email;
    const password = dataReceived[dataReceived.length - 1].password;
    const body = "As dori crearea unui cont pe portalul e-Radauti cu urmatoarele date: <br>" + name + "<br>" + email + "<br>" + "password" + password;
    const mailOptions = {
      from: "Adaugare User pe portal-ul e-Radauti",
      to: "mail",
      subject: "Adaugare user pe portalul e-Radauti",
      bcc: "bcc",
      html: body,
    };
    console.log(mailOptions);
    await transporter.sendMail(mailOptions);
    return null;
  });

Edit: I've updated the code with @Dharmaraj suggestion and also I have the Blaze(Pay as you go) plan

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've solved this by creating a new transporter and I've added it inside the function:

exports.sendMailUser =
  functions.firestore.document("collection/Users").onUpdate(async (snapshot, context) => {
    const transporter2 = nodemailer.createTransport({
      host: host,
      port: 465,
      debug: true,
      secure: true, 
      auth: {
        user: user,
        pass: pass,
      },
    });
    var data = snapshot.after.data();
    var dataReceived = data.users;
    var body = "As dori crearea unui cont pe portalul e-Radauti cu urmatoarele date: <br>" + dataReceived[dataReceived.length - 1].name + "<br>" + dataReceived[dataReceived.length - 1].email + "<br>" + "password:" + dataReceived[dataReceived.length - 1].password;
    var mailOptions = {
      from: "Adaugare User pe portal-ul e-Radauti",
      to: to,
      subject: "Adaugare user pe portalul e-Radauti",
      bcc: bcc,
      html: body,
    };
    //console.log(mailOptions);
    await transporter2.sendMail(mailOptions);
    return null;
  });

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