A
A
ArtGMlg2021-02-12 18:20:58
JavaScript
ArtGMlg, 2021-02-12 18:20:58

Why does nodemailer only send emails from localhost?

On the node.js express server, I have a router that is responsible for sending emails when a user registers on the site.
Router:

var express = require('express');
var router = express.Router();
var fs = require('fs');
const nodemailer = require('nodemailer');

router.post('/send/confirmMail', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.contentType('json');
  res.setHeader('Content-Type', 'application/json');

  var transporter = nodemailer.createTransport({
    host: "smtp.mail.ru",
    secureConnection: true,
    port: 465,
    auth: {
      user: /*имя пользователя*/,
      pass: /*пароль*/
    },
    tls: {
        // do not fail on invalid certs
        rejectUnauthorized: false
    }
  });

  transporter.sendMail({
    from: '[email protected]',
    to: req.body.email,
    subject: 'Подтверждение e-mail адреса.',
    html: /*html-письмо*/
  }, (error, info) => {
    if (error) {
      res.status(500).send(JSON.stringify({err: error, inf: info}));
      return console.log(error);
    } else {
      res.status(200).end();
    }
  });

});

module.exports = router;


When I send an email from localhost this way, everything works. However, when sending a letter, when the application is running on the hosting, the following error arrives in response:
address: "217.69.139.160"
code: "ESOCKET"
command: "CONN"
errno: "ETIMEDOUT"
port: 465
syscall: "connect"


The nodemailer git has this explanation: "Check your firewall settings. The timeout usually occurs when you try to open a connection on a port that is firewalled either on the server or on your computer." In that case, how should I configure the firewall on the server?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question