guileen / node-sendmail

send mail without setting up a SMTP server
http://guileen.github.com/node-sendmail
MIT License
559 stars 108 forks source link

Error: " can not connect to any SMTP server" #19

Closed tbalouet closed 7 years ago

tbalouet commented 7 years ago

Expected Behavior

Using your package to send mails, the server was unable to send anything. Here's the server code I used:

var sendmail         = require('sendmail')({
  logger: {
    debug: console.log,
    info: console.info,
    warn: console.warn,
    error: console.error
  },
    silent: false
})

sendmail({
  from: 'no-reply@yourdomain.com',
  to: 'thomas@lucidweb.io',
  subject: 'test sendmail',
  html: 'Mail of test sendmail ',
}, function(err, reply) {
  console.log(err && err.stack);
  console.dir(reply);
});

And here's the console error I got:

mx resolved:  [ { exchange: 'alt3.aspmx.l.google.com', priority: 10 },
  { exchange: 'alt4.aspmx.l.google.com', priority: 10 },
  { exchange: 'alt1.aspmx.l.google.com', priority: 5 },
  { exchange: 'alt2.aspmx.l.google.com', priority: 5 },
  { exchange: 'aspmx.l.google.com', priority: 1 } ]
Error on connectMx for:  { exchange: 'alt3.aspmx.l.google.com', priority: 10 } { [Error: connect ETIMEDOUT 74.125.23.27:25]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '74.125.23.27',
  port: 25 }
Error on connectMx for:  { exchange: 'alt4.aspmx.l.google.com', priority: 10 } { [Error: connect ETIMEDOUT 173.194.72.27:25]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '173.194.72.27',
  port: 25 }
Error on connectMx for:  { exchange: 'alt1.aspmx.l.google.com', priority: 5 } { [Error: connect ETIMEDOUT 173.194.73.27:25]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '173.194.73.27',
  port: 25 }
Error on connectMx for:  { exchange: 'alt2.aspmx.l.google.com', priority: 5 } { [Error: connect ETIMEDOUT 74.125.200.27:25]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '74.125.200.27',
  port: 25 }
Error on connectMx for:  { exchange: 'aspmx.l.google.com', priority: 1 } { [Error: connect ETIMEDOUT 74.125.195.27:25]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '74.125.195.27',
  port: 25 }
error on connectMx Error: can not connect to any SMTP server
    at tryConnect (D:\My Files\work\www\lucidweb\node_modules\sendmail\sendmail.js:78:49)
    at Socket.<anonymous> (D:\My Files\work\www\lucidweb\node_modules\sendmail\sendmail.js:84:15)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1253:8)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)
Error: can not connect to any SMTP server
    at tryConnect (D:\My Files\work\www\lucidweb\node_modules\sendmail\sendmail.js:78:49)
    at Socket.<anonymous> (D:\My Files\work\www\lucidweb\node_modules\sendmail\sendmail.js:84:15)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1253:8)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickCallback (node.js:356:17)
undefined

Context

I'm trying to send a mail with informations received from a form

Your Environment

Windows 10 NodeJS v4.4.3

GreenPioneer commented 7 years ago

Where are you trying to use this from? home or work ?

djcaesar9114 commented 7 years ago

I've got the same here for me. I think the majority of companies have a kind of "white list" of IPs, to prevent DDOS. If you're trying it from your computer, chances are that your IP is not in that list.

Just try it on a VPS you rent anywhere, it should work (well it did for me!)

tbalouet commented 7 years ago

I was trying this from work. But actually after trying this in production mode on an Ubuntu server, it seems to be working. Maybe it is a Windows related problem?

CherryNerd commented 7 years ago

I've had the same sort of problem, but it was resolved the moment I send a mail from the domain the app was installed on. E.g. I have a Digital Ocean droplet with the domain geex.company on it and mails are sent without any problem, but the moment I try to send a mail from a domain that is not pointed by DNS to that VPS, like "outlook.com", it gets blocked by gmail servers and other services list it as "spam".

skerit commented 7 years ago

While testing the script at home I ran into the same problem, this was because my ISP blocks port 25 by default.

Would be nice if the port can also be manually set, like the devPort.

GreenPioneer commented 7 years ago

@skerit drop a PR and ill be sure to look at it. If not ill just be sure to write it down and take it into account later

eezing commented 7 years ago

From Comcast docs on port 25: "Comcast recommends the use of the industry-recommended port 587 with TLS/SSL enabled...".

RevealedFrom commented 7 years ago

Help me understand how node-sendmail works. Is the computer running this module connecting directly to the MX servers of every email recipient? If so, I think some hosting companies like 1and1 that open SMTP ports only to its own network will prevent this from working. Also, SPF would likely fail during development time when I am running off my PC connecting from anywhere.

sebringj commented 6 years ago

I am using node mailer with SendGrid

    "nodemailer": "^2.7.0",
    "nodemailer-smtp-transport": "^2.7.2",

I was stuck not being able to send out to port 25 locally. SendGrid allows port 2525 so I tried that and worked! Apparently, my ISP does not block port 2525 so I can do local development easily.