connect ECONNREFUSED 127.0.0.1:587 (nodemailer + mailtrap) - node.js

I've been trying to get the basic combination of nodemailer, using a mailtrap.io account to work, and striking out.
Here is my app.js:
const nodemailer = require('nodemailer');
let transport = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
// secure: true,
auth: {
user: "myusername",
pass: "mypassword"
},
debug: true,
logger: true
});
let scrapeEmailMessage = {
//from: 'myemail#gmail.com',
to: 'myemail#gmail.com',
subject: 'Hello World',
text: 'hello world'
};
let mailTransporter = nodemailer.createTransport(transport);
mailTransporter.sendMail(scrapeEmailMessage, function(err, data) {
if(err) {
console.log(err);
} else {
console.log('Email sent successfully');
}
});
And here is the error output I'm getting:
[2020-11-10 14:32:20] DEBUG Creating transport: nodemailer (6.4.15; +https://nodemailer.com/; SMTP/6.4.15[client:6.4.15])
[2020-11-10 14:32:20] DEBUG Creating transport: nodemailer (6.4.15; +https://nodemailer.com/; SMTP/6.4.15[client:6.4.15])
[2020-11-10 14:32:20] DEBUG Sending mail using SMTP/6.4.15[client:6.4.15]
[2020-11-10 14:32:20] DEBUG [YlvPyvxQxE] Resolved localhost as 127.0.0.1 [cache miss]
[2020-11-10 14:32:22] ERROR [YlvPyvxQxE] connect ECONNREFUSED 127.0.0.1:587
[2020-11-10 14:32:22] DEBUG [YlvPyvxQxE] Closing connection to the server using "destroy"
[2020-11-10 14:32:22] ERROR Send Error: connect ECONNREFUSED 127.0.0.1:587
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
errno: 'ECONNREFUSED',
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
I've tried a number of things to fix it, and continually get this same error message:
Turning on the "less secure apps" options in Gmail and using the above code to try to connect to smtp.gmail.com instead.
Manually editing the port numbers in the code above.
Toggling secure mode on and off in the code above.
Adding Windows Defender Firewall exceptions on ports 587, 465, as well as a couple others just for fun to see if they would work.
Disabling Windows Defender Firewall completely.
Running the code on other computers on my home network.
Checking "netstat -an" to see if ports 587 or 465 are listed. They are not, but is this port open all the time or only opened when needed? Could this be the issue?
Anyone have any ideas on what might be going on here? I'm just a normal guy using his home internet connection to write a small program to send himself an email alert once a day. Could my ISP be blocking this or something?
EDIT- Adding a couple new things I've tried that haven't worked:
Transport option "ignoreTLS: true/false" (tried both)
Transport option "requireTLS: true/false" (tried both)

You are creating two transporter.
Instead of this :
let mailTransporter = nodemailer.createTransport(transport);
and
mailTransporter.sendMail()
Do this :
transport.sendMail()

modify;
let transport = nodemailer.createTransport({
to be;
let transport = {
and remove the closing parentheses; }); to be };

I got this error, and it's because I was using port 25 instead of port 2525. It says 25 is an option but seems to not work for me.

Related

Managed DigitalOcean Redis instance giving Redis AbortError

I setup managed redis and managed postgres on digital ocean. Digital ocean gave me a .crt file, I don't know what to do with this, so didn't do anything with it. Can this be the root of the problem below:
Or do I have to allow docker container to reach outside of the container on the rediss protocol?
I dockerized a node app and then put this container onto my droplet. I have my droplet and managed redis and postgres in same region (SFO2). It connects to redis using this url:
url: 'rediss://default:REMOVED_THIS_PASSWORD#my-new-app-sfo2-do-user-5053627-0.db.ondigitalocean.com:25061/0',
I then did ran my docker container with docker run.
It then gives me error:
node_redis: WARNING: You passed "rediss" as protocol instead of the "redis" protocol!
events.js:186
throw er; // Unhandled 'error' event
^
AbortError: Connection forcefully ended and command aborted. It might have been processed.
at RedisClient.flush_and_error (/opt/apps/mynewapp/node_modules/redis/index.js:362:23)
at RedisClient.end (/opt/apps/mynewapp/node_modules/redis/lib/extendedApi.js:52:14)
at RedisClient.onPreConnectionEnd (/opt/apps/mynewapp/node_modules/machinepack-redis/machines/get-connection.js:157:14)
at RedisClient.emit (events.js:209:13)
at RedisClient.connection_gone (/opt/apps/mynewapp/node_modules/redis/index.js:590:14)
at Socket.<anonymous> (/opt/apps/mynewapp/node_modules/redis/index.js:293:14)
at Object.onceWrapper (events.js:298:28)
at Socket.emit (events.js:214:15)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on RedisClient instance at:
at /opt/apps/mynewapp/node_modules/redis/index.js:310:22
at Object.callbackOrEmit [as callback_or_emit] (/opt/apps/mynewapp/node_modules/redis/lib/utils.js:89:9)
at Command.callback (/opt/apps/mynewapp/node_modules/redis/lib/individualCommands.js:199:15)
at RedisClient.flush_and_error (/opt/apps/mynewapp/node_modules/redis/index.js:374:29)
at RedisClient.end (/opt/apps/mynewapp/node_modules/redis/lib/extendedApi.js:52:14)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'NR_CLOSED',
command: 'AUTH',
args: [ 'REMOVED_I_DONT_KNOW_IF_THIS_IS_SENSITIVE' ]
The redis protocol is different from rediss because the latter uses TLS connection. DigitalOcean Managed Redis requires the connections to be made over TLS, so you have to use rediss. However, I couldn't find any info about the TLS certificate provided by DigitalOcean to connect to the Managed Redis service.
Based on your error message, I presumed you're using this redis package. If that's the case, you can pass empty TLS object option in the connection string like so:
const Redis = require('redis')
const host = 'db-redis.db.ondigitalocean.com'
const port = '25061'
const username = 'user'
const password = 'secret'
const url = `${username}:${password}#${host}:${port}`
const client = Redis.createClient(url, {tls: {}})
Further reading/source:
SSL connections arrive for Redis on Compose
Connecting to IBM Cloud Databases for Redis from Node.js
I solved this. Below are snippets from config/env/production.js
Sockets
For sockets, to enable rediss you have to pass in all options through adapterOptions like this:
sockets: {
onlyAllowOrigins: ['https://my-website.com'],
// pass in as adapterOptions so it gets through to redis-adapter
// as i need it "rediss" but this url is not supported i get an error.
// so i need to pass in `tls` empty object. and i see he moves things into
// `adapterOptions` here here - https://github.com/balderdashy/sails-hook-sockets/blob/master/lib/configure.js#L128
adapterOptions: {
user: 'username',
pass: 'password',
host: 'host',
port: 9999,
db: 2, // pick a number
tls: {},
},
adapter: '#sailshq/socket.io-redis',
},
Session
For session, pass tls: {} empty object to config:
session: {
pass: 'password',
host: 'host',
port: 9999,
db: 1, // pick a number not used by sockets
tls: {},
cookie: {
secure: true,
maxAge: 24 * 60 * 60 * 1000, // 24 hours
},
},

Node.js - FTP through HTTP Tunnel (FTP over HTTP Proxy)

I am looking for an opportunity to connect FTP-Server via HTTP-Proxy-Server. I tried different npm packages (jsftp, ftp etc.), but the connection does not work. I have tried a few SOCKS packages but they seem outdated. Here is an example from the package jsftp. Unfortunately, the example does not work and I can not find any solution
const {SocksClient} = require('socks');
const ftp = new Ffp({
host: 'localhost',
port: 3333,
user: 'user',
pass: 'password',
createSocket: ({port, host}, firstAction) => {
return SocksClient.createConnection({
proxy: {
ipaddress: '159.203.75.200'
port: 1080,
type: 5
},
command: 'connect',
destination: {
host,
port
}
})
}
})
This solution worked for me. However, it uses platform-dependent packages and is only commercially available starting from USD 289.
This solution looked promising, but I couldn't get it to work properly. It created files I wanted to copy, but they always ended up being empty.

{ [Error: timedout while connecting to smtp server] code: 4, smtp: undefined }

I am going to send mail in nodejs. So I have installed emailjs.
I have configured the script as the followings.
emailjs = require('emailjs');
var server = emailjs.server.connect({
user:"my gmail address",
password:"gmail passs word",
host:"smtp.gmail.com",
ssl:true,
port: 456
});
server.send({
text: "message",
from:"LLVC <my outlook mail>",
to:"<my outlook mail>",
subject:"Subject"
},
function (err, message) {
console.log(err || message);
});
But I got the errors
{ [Error: timedout while connecting to smtp server] code: 4, smtp: undefined }
I want to fix them.
Thanks.
It's port 465, not 456.
If you tried configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL).
https://support.google.com/mail/answer/78775?hl=en
Just in case someone else is looking for an answer. What worked for me was setting ssl to true and tls to false. Adding smtp port didn't help. With that been said the following are valid smtp ports: 25, 465, 587, and 2525. I hope this helps somebody else.

intern 2 configuration for BrowserStack behind a proxy

I'm unsure what the configuration should be running intern 2 tests against BrowserStack when running behind a proxy/firewall and currently seeing errors/timeouts.
My Current configuration is:
proxyPort : 9000,
proxyUrl : 'http://localhost:9000',
tunnel : 'BrowserStackLocal',
tunnelOptions : {
username : 'myusername',
accessKey : 'myaccesskey',
hostname : '<myproxyip>',
proxy : 'http://<myproxyip>:<myproxyport>'
}
I don't think I need hostname however if I remove that I immediately see the error getaddrinfo ENOTFOUND.
If use the above configuration it seems to get further, waits for a while then see:
Listening on 0.0.0.0:9000
Starting tunnel...
BrowserStackLocal v3.3
Connecting to BrowserStack using WebSocket protocol...
Connected.
Ready
Error: [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] connect ETIMEDOUT
Error: connect ETIMEDOUT
at errnoException <net.js:904:11>
at Object.afterConnect [as oncomplete] <net.js:895:19>
FATAL ERROR
Error: [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] connect ETIMEDOUT
Error: connect ETIMEDOUT
at errnoException <net.js:904:11>
The [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] url doesn't seem right. Obviously I have this misconfigured & would appreciate any advice. I do struggle to understand intern's documentation when running behind a proxy.
It looks like you are behind some kind of proxy.
When you are behind proxy server, in order to use Intern with BrowserStack, you need to do two things:
Get Local Testing connection to work with your proxy, which you are doing, and you can see success message.
You have to make sure the node process that runs the Intern test works with your proxy. To enable proxy in a node application, the easiest option is to use global-tunnel npm package. There is a step-by-step guide available here.
Would love to answer any queries you might have! Do drop in a mail at support#browserstack.com
Umang,
BrowserStack Support.
I'm not sure but I think there is a bug in browserStack.js. Some proxy support is missing there I think. When I use configuration browserstack_conf.js as shown below tests run okay but there is an error message when Browserstack tries to publish the test results back to www.browserstack.com
[09:43:06] E/launcher - connect ETIMEDOUT 54.152.200.70:443
[09:43:06] E/launcher - Error: connect ETIMEDOUT 54.152.200.70:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[09:43:06] E/launcher - Process exited with error code 199
I can fix this error with following steps:
npm install -g http-proxy-agent
Edit browserStack.js (located for example in C:\Users\myuser\AppData\Romaing\npm\node_modules\protractor\built\driverProviders\ add a require for this and initialize a agent and add to request.
For example add require top of browserStack.js
var HttpProxyAgent = require('http-proxy-agent');
And change the section with options to
let options = {
hostname: 'www.browserstack.com',
port: 443,
path: '/automate/sessions/' + session.getId() + '.json',
method: 'GET',
headers: headers//,
agent: new HttpProxyAgent('http://myproxy:3128')
};
I start Protractor with configuration below
// browserstack.conf.js
var browserstack = require('browserstack-local');
exports.config = {
specs: ['spec.js'],
webDriverProxy: 'http://myproxy:3128',
browserstackUser: 'myuser',
browserstackKey: '*****',
capabilities: {
project: 'BrowserStack (beyond Proxy)',
browserName: 'Chrome',
browser_version: '50.0',
os: 'OS X',
os_version: 'Yosemite',
'browserstack.local': true,
'browserstack.debug': true
},
// Code to start browserstack local before start of test
beforeLaunch: function(){
console.log("Connecting local");
return new Promise(function(resolve, reject){
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': '*****',
'proxyHost': 'myproxy', 'proxyPort': '3128',
'binarypath': 'C:\\Users\\myuser\\Downloads\\BrowserStackLocal-win32\\BrowserStackLocal.exe'},
function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
afterLaunch: function(){
return new Promise(function(resolve, reject){
exports.bs_local.stop(resolve);
});
}
};

nodejs emailjs connect econnrefused, smtp

my node server starts fine, is running fine until i'm trying to send an email with emailjs...
this exception is thrown:
error : code 5
error : previous { [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
error : smtp undefined
my code:
var ES = require('./email-settings');
var EM = {};
module.exports = EM;
EM.server = require("emailjs/email").server.connect({
host : ES.host,
user : ES.user,
password : ES.password,
ssl : true,
port : 465
});
EM.dispatchResetPasswordLink = function(account, callback)
{
EM.server.send({
from : ES.sender,
to : account.email,
subject : 'Password Reset',
text : 'something went wrong... :(',
attachment : EM.composeEmail(account)
}, callback );
}
in email-settings i define host, user, password... they are not undefined. my smtp-server is gmail. do i have to define any other settings? maybe for my gmail-account? is emailjs using port 80 or so? my app is running on 8003
im looking for a solution for quite a long time now... thx for help :)
You need to unlock captcha code in gmail. As below link
https://accounts.google.com/b/0/displayunlockcaptcha

Resources