Nodemailer: ECONNREFUSED - works locally but on prod server I get ECONNREFUSED

Created on 23 Sep 2013  Â·  18Comments  Â·  Source: nodemailer/nodemailer

Hi

I've used the following code to connect to my mandrill SMTP account. When I run the server code locally on my mac it works, but on my production box (ubuntu) it doesn't. I also tried on a debian Raspberri Pi with the same issue.

Code:

//nodemailer
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Mandrill",
auth: {
user: "[email protected]",
pass: smtppassword
}
});

var send = function(recipient, subject, text) {

smtpTransport.sendMail({
   from: "NAME <[email protected]>", // sender address
   to: recipient, //recipient
   subject: subject, // Subject line
   text: text // plaintext body
}, function(error, response){
   if(error){
       console.log(error);
   }else{
       console.log("Emailer.js - message sent: " + response.message);
   }
});

};

Running locally works fine. Running on ubuntu I get the following bug every time:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }

anyone know how to fix this? I've been googling all morning. I don't think it's a port issue. Is it postfix?

All 18 comments

Can you access the Mandrill server directly from your service? If you run the following command in your server:

nc smtp.mandrillapp.com 587

The output should look like this:

220 smtp.mandrillapp.com ESMTP

ECONNREFUSED is usually a firewall issue but not always

yes. I get the same.

Mr Hugh Halford-Thompson
+44 (0)7789231917

http://www.3distributed.com/

http://www.quickbitcoin.co.uk/

http://hughht5.blogspot.co.uk/ http://www.techcrunchlite.com/

Flat 2
Minus One House
Lyttleton Road
Leyton
E10 5NQ
UK

Too brief? Here's why! http://emailcharter.org

On 23 September 2013 15:17, Andris Reinman [email protected] wrote:

Can you access the Mandrill server directly from your service, if you run
the following command in your server:

nc smtp.mandrillapp.com 587

The output should look like this:

220 smtp.mandrillapp.com ESMTP

—
Reply to this email directly or view it on GitHubhttps://github.com/andris9/Nodemailer/issues/192#issuecomment-24922837
.

root@ubuntu:/var/www/finansist# nc localhost 25
220 realdomainame ESMTP Postfix (Ubuntu)

I get the same error trying to connect to the local mail server. no firewall.

http://pastebin.com/w9Kb4ysh

C:\Users\mark\Desktop\tests>node new
SMTP Configured
Sending Mail
Express server listening on port 3000 in development mode
Error occured
connect ECONNREFUSED

the error come to me?

but changing the service name to Mandrill its working fine? And it was the first email i am sending .

Nodemailer v1.0 includes a new SMTP client. Keep me updated if the issue still occurs.

I'm getting a similar error. Locally sending email works great but on our test server it fails. I'm using Nodemailer 1.1.1

var transporter = nodemailer.createTransport({
  service: 'Gmail',
  auth: { user: '[email protected]',
          pass: 'mypassword' },
});

When trying to send an email on our test server I get and ECCONNREFUSED error.

On the test server

nc smtp.gmail.com 587

Prints

220 mx.google.com ESMTP ar1sm7438411lbc.3 - gsmtp

The test server is sending emails without any problems from a legacy web framework running on it. Thus I don't think it's a firewall related issue.

Could you try to access the port 465 from your test server as well, since thats the default for gmail service. This is a secure port, so use openssl instead of nc

 openssl s_client -crlf -connect smtp.gmail.com:465

and the result should end with

220 mx.google.com ESMTP ko8sm12142123wjc.11 - gsmtp

Yes, of course.

The output from running that command is:

connect: Connection refused
connect:errno=111\

That looks like a problem!

Same problem but when typing openssl s_client -crlf -connect smtp.gmail.com:465
returns 220 mx.google.com ESMTP ko8sm12142123wjc.11 - gsmtp
What is going on!?

can it be after I've installed domain package?

I get the same error after updating nodemailer both locally and on production. (Mandrill)

What was wrong was that createTransport's header has changed. It no longer takes the "SMTP" string as the first parameter (so it got read as options).

Is there a solution to this problem? I'm still experiencing this issue.

Usually the problem is when you have upgraded nodemailer to v1.0 and use the 0.x API (dev server uses 0.x, production uses 1.0) or there are firewall issues (smtp ports are disabled in production).

guys, sorry for my poor english!
i have same problem. (digital ocean droplet/debian6-64)
i try
"openssl s_client -crlf -connect smtp.gmail.com:465" and receive this
"220 mx.google.com ESMTP u6sm18957700qgu.18 - gsmtp"
and nodejs code is ....
var nodemailer = require('nodemailer');
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
user: "[email protected]",
pass: "????????" // i change pwd for privacy
}
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: '[email protected] [email protected]',
// Comma separated list of recipients
to: '"[email protected]" [email protected]',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔',
// plaintext body
text: 'Hello to myself!',
// HTML body
html:'

Hello to myself

'+
'

Here\'s a nyan cat for you as an embedded attachment:

'
};
console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
transport.close(); // close the connection pool
});

yehhhh, this code works
1st - "https://accounts.google.com/DisplayUnlockCaptcha"
2nd - this code below...
.......
Object.defineProperty(global, '__stack', {
get: function() {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack) {
return stack;
};
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
});
Object.defineProperty(global, '__line', {
get: function() {
return __stack[1].getLineNumber();
}
});
console.log( __line +'.1.');
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var envelope = {
debug: true,
host: 'smtp.gmail.com',
port: 465,
secure: true, /* SSL=true _/
auth: {
user: '[email protected]',
pass: '????????' /_ change for my security */
},
maxConnections: 5,
maxMessages: 10
};
console.log( __line +'.2');
console.dir(envelope);
var transporter = nodemailer.createTransport(smtpTransport(envelope));
var mail = {
from: '[email protected]',
to: '[email protected]',
subject: 'hello',
text: 'hello world!'
};
console.log(__line +'.3.Sending Mail');
console.dir(mail);
transporter.sendMail(mail, function(error){
if(error){
console.log('.3.1.Error occured');
console.dir(error);
return;
}
console.log('.3.2.Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
transporter.close(); // close the connection pool
});
console.log( __line +'.4.');

this forum might have some insights into your econnrefused problem

someone could fix the problem using Digital Ocean ? I can't send emails from my server, but I can locallly.

Was this page helpful?
0 / 5 - 0 ratings