Hisham Mubarak
Hisham Mubarak

Reputation: 1609

Connection timeout error when sending mail from Zohomail using Nodemailer

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: '<[email protected]>',
        pass: '<myemailpassword>'
    }
});

var mailOptions = {
  from: "<[email protected]>",
  to: "<[email protected]>",
  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?

Upvotes: 2

Views: 3980

Answers (1)

Kalana Demel
Kalana Demel

Reputation: 3266

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

Upvotes: 5

Related Questions