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

179
Visualizações
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 à 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