Can't connect to SMTP server using TLS

38 Views Asked by At

I use these settings use the apache java mail client and it works.

  smtp:
    host: host
    port: 587
    sslEnabled: false
    sslTrust: trust
    tlsEnabled: true

I’m trying to recreate this in node.js with nodemailer

var transporter = nodemailer.createTransport({
  host: host,
  port: 587,
  secure: true, // upgrade later with STARTTLS
  auth: {
    user: email,
    pass: pass,
  },
  requireTLS: true,
  tls: {
    rejectUnauthorized: false,
    servername: trust
  },
  debug: true
});
 
var mailOptions = {
  from: email,
  to: email,
  subject: 'test subject',
  text: 'test text'
};

I kept trust and host the same for both.

These settings return the following error

Error: connect ETIMEDOUT address:587
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
  errno: -60,
  code: 'ESOCKET',
  syscall: 'connect',
  address: '155.56.68.170',
  port: 587,
  command: 'CONN'
}
email error: Error: connect ETIMEDOUT address:587
email error: Error: connect ETIMEDOUT address:587

This email server says it requires the following configuration

- Port: 465
  SSL: required
or
- Port: 587
  STARTTLS: required

I have tried with all combinations of port 465, 587, secure, and requireTLS.

I don't have a certificate for SSL.

1

There are 1 best solutions below

0
Hardik On

enter image description here

Using secure:false,

 var transporter = nodemailer.createTransport({
  host: host,
  port: 587,
  secure: false, 
  auth: {
    user: email,
    pass: pass,
  },
  requireTLS: true,
  tls: {
    rejectUnauthorized: false,
    servername: trust
  },
  debug: true
});
 
var mailOptions = {
  from: email,
  to: email,
  subject: 'test subject',
  text: 'test text'
};

not other error for this code