2

Below is my Node app.js code. With these settings, I am receiving a connection timeout error. Any idea what I am missing here?

var nodemailer = require("nodemailer");

var transporter = nodemailer.createTransport({
  host: 'smtp.zoho.com',
    port: 465,
    secure: true, // use SSL
    auth: {
        user: '<myemail@example.com>',
        pass: '<myemailpassword>'
    }
});

var mailOptions = {
  from: "<fromemail@example.com>",
  to: "<toemail@example.com>",
  subject: "Hello",
  generateTextFromHTML: true,
  html: { path: './tmpl.html' }
};

transporter.sendMail(mailOptions, function(error, response) {
  if (error) {
    console.log(error);
  } else {
    console.log(response);
  }
  transporter.close();
});

Error shown

{ Error: Connection timeout
    at SMTPConnection._formatError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:557:19)
    at SMTPConnection._onError (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:530:20)
    at Timeout._connectionTimeout.setTimeout (/home/ubuntu/workspace/mailapp/node_modules/nodemailer/lib/smtp-connection/index.js:248:18)
    at ontimeout (timers.js:380:14)
    at tryOnTimeout (timers.js:244:5)
    at Timer.listOnTimeout (timers.js:214:5) code: 'ETIMEDOUT', command: 'CONN' }

Can anyone please help me?

Kalana Demel
  • 3,220
  • 3
  • 21
  • 34
Hisham Mubarak
  • 1,559
  • 3
  • 22
  • 28

1 Answers1

5

Some cloud providers disable ports like 465 and 587, try using port 2525 instead of 465.

Update

Since you're using Cloud9 for this I found out they have blocked all outbound smtp calls from their servers. If you need to send anyways you need to choose another cloud provider or use one of their recommended services.

https://community.c9.io/t/how-can-i-send-email-from-my-app/1262

Kalana Demel
  • 3,220
  • 3
  • 21
  • 34