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

178
Vistas
code: 'ECONNRESET', response: undefined, Error coming when attempting to send a mail via a SMTP server

We have a usecase to send a mail to end users regarding few information.

The current way which we are doing is using a python script, which inturn is called from a Express JS script:

Current code:

  request.post(MailURL)
.set('Content-Type', 'application/json')
.send({
  emailId: <email_ids>,
  ccId: <email_ids>,
  emailSubject: `TEST SUBJECT`,
  emailBody: `TEST BODY`
})
.end((err, res) => {
  if (err) {
    logger.error(logMessage, 'Error when sending a mail', err);
    return res.status(500).json({
      message: 'Error when sending a mail',
      error: err,
    });
  }
  logger.info(logMessage, 'Successfully sent mail');
});

Here Mail URL is the local Express container URL.

Python Code:

    for send_attempt in range(1, max_retry+1):
    try:
        parsed_args = parseArgs()
        mailer = Mailer(parsed_args.recipients, parsed_args.subject, parsed_args.cc)
        mailer.attach_html_body()
        mailer.send_message()
        mailer.remove_file()
        break
    except socket.error as socket_error:
        logging.warning("Attempt %d to send email failed...", send_attempt)
        logging.error("Socket Error: %s", os.strerror(socket_error.errno))
        if send_attempt >= max_retry:
            logging.error("Could not send email after %d attempts.", max_retry)

We are trying to catch the exception, but still the Error is coming, due to which the Express container is going down with below Error:

{ Error: socket hang up\n    at createHangUpError (_http_client.js:331:15)\n    at Socket.socketOnEnd (_http_client.js:423:23)\n    at emitNone (events.js:111:20)\n    at Socket.emit (events.js:208:7)\n    at endReadableNT (_stream_readable.js:1055:12)\n    at _combinedTickCallback (internal/process/next_tick.js:138:11)\n    at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET', response: undefined }


   return res.status(500).json({
               ^

TypeError: Cannot read property 'status' of undefined

Could someone help what is going wrong here, or how we can prevent container from going down?

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