Nodemailer with Dreamhost error: connection timed out

software development

#1

I am trying to configure Nodemailer with Dreamhost SMTP and having an error that I can’t figure out. I’ve tried different ports with no luck. Here is my setup code:

'use strict';
 const nodemailer = require('nodemailer');

   // create reusable transporter object using the default SMTP transport
   var transporter = nodemailer.createTransport({
    host: 'sub5.mail.dreamhost.com',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
        user: 'name@mywebsite.com',
        pass: 'mypassword'
    }
});

// setup email data with unicode symbols
var mailOptions = {
    from: 'name@mywebsite.com', // sender address
    to: 'email@gmail.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    console.log('called');
    if (error) {
        return console.log(error);
    }
    console.log('Message sent: %s', info.messageId);

});

and the error:

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

#2

The port looks correct but the secure set to false looks weird to me: it should be true. Have you to connect with an email client like Thunderbird with that configuration?

You may want to experiment with other options to try and force TLS, too. Let us know how that goes.


#3

I looked at your post because I was doing the same thing, and doing the following worked:

var email = user.email;
var fromEmail = encodeURIComponent('support@mydomain.com');
const fromPassword = encodeURIComponent('mypassword');
var APP_NAME = 'My App';
var mailOptions = {
    from: `${APP_NAME} <support@mydomain.com>`,
    to: email
};
var transporter = nodemailer.createTransport({
    host: 'mail.mydomain.com',
    port: 587,
    secure: false, // true for 465, false for other ports
    requireTLS: true, //Force TLS
    tls: {  
        rejectUnauthorized: false
    },
    auth: {
        user: 'support@mydomain.com,
        pass: 'mypassword'
    }
});

mailOptions.subject = `Charge failed for ${APP_NAME}!`;
mailOptions.text = `Your charge for next month of usage for ${APP_NAME} failed. Please open the app and update your payment information.\n\nSincerely,\n${APP_NAME}`;
transporter.sendMail(mailOptions).then(() => {
    console.log('Charge failed email sent to:', email);
});

#4

Did you have to do anything inside Dreamhost to configure? I’m using your solution and I’m getting the same error.


#5

The configuration I have is this:

Email Client Configuration

To check your email go to webmail, then enter the first part of your email address, before the @, and your password to sign in.
If you need help setting up your email address in your email client, please see the following article on the DreamHost Wiki: Email Client Configuration.

Incoming mail server: mail.<DOMAIN>.com 
Incoming mail server type: POP3 or IMAP (your choice) 
Incoming mail server username: support@<DOMAIN>.com (use the whole thing!)

Outgoing (SMTP) mail server: mail.<DOMAIN>.com
My server requires authentication: checked. (use same settings as incoming mail server) 
Use secure password authentication: not checked.

I did not touch ports. I’m sending emails from Google Firebase.


#6

Make sure you’re using the right SMTP server name for your account. Found out which one by reading the docs. If you’re using the right server, share more details about your setup please.


#7

Well as is typical the solution was simple and a bit stupid. I’m still using the same setup as yaizudamashii, only for host I used the sub5 dreamhost server rather than my mail.domain.com. For those reading in the future, the problem was I was using Cloud9 as my development environment. I believe C9 has some kind of firewall in place which was blocking the 587 port. When I deployed the application it worked.


#8

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.