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

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.

Related

connect ECONNREFUSED 127.0.0.1:587 (nodemailer + mailtrap)

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.

Is there a workaround in the nodemailer package for other services?

I noticed by looking at nodemailer docs that they didn't support unoeruo mails as a service. Is there a workaround or do i need to use another package. And if i need to use another is there anyone you recommend?
The "well know services" are just for your convenience. You can always create the SMTP Transport on your own, while using the settings from unoeuro
Assuming you are using typescript, it would look like this. Just set user and pass to your credentials:
import * as Smtp from 'nodemailer';
const options = {
host: "websmtp.unoeuro.com",
port: 587,
secure: true,
auth: {
user: "YOUR-LOGIN",
pass: "YOUR-PASSWORD"
};
};
const transport = Smtp.createTransport(options);
//do something with transport:
transport.sendMail({...});

How to pass multiple host url's in the transport object for createTransport function in nodemailer

Is it possible to configure multiple host value with their respective ports in transport object of createTransport function of nodemailer library.
Right now my code is:
var transport = {
host: "devint.test.com",
port: 22,
auth: {
user: "test",
pass: "test"
}
}
let transporter = nodemailer.createTransport(transport);
In above transport object, I have passed single host i.e. devint.test.com in host property of transport object. In my application, there are multiple email server, So I want to pass multiple host name and their port in the host and port property of transport object. Is there any way to do?
PS: For now forget about that reason for having multiple email server, its long story.

sending OSC between machines on a LAN using Node.js and OSC.js

Has anyone created a working setup where OSC is being sent between machines on a LAN using Node.js? Ideally, using Colin Clark's osc.js package?
I have what I think should be a pretty simple example, except that it doesn't work - I get an EADDRNOTAVAIL error, which implies that the remote address isn't available. I can ping the other laptop successfully, however.
Here's the code and the error, for reference:
Sending code (laptop at 192.168.0.5):
var osc = require("osc");
var udp = new osc.UDPPort({
localAddress: "127.0.0.1", // shouldn't matter here
localPort: 5000, // not receiving, but here's a port anyway
remoteAddress: "192.168.0.7", // the other laptop
remotePort: 9999 // the port to send to
});
udp.open();
udp.on("ready", function () {
console.log("ready");
setInterval(function () {
udp.send({
address: "/sending/every/second",
args: [1, 2, 3]
})
}, 1000);
});
Receive code (on laptop at 192.168.0.7):
var osc = require("osc");
var udp = new osc.UDPPort({
localAddress: "192.168.0.7",
localPort: 9999
});
udp.open();
udp.on("ready", function () {
console.log("receiver is ready");
});
udp.on("message", function(message, timetag, info) {
console.log(message);
});
Here's the error I get when I run the sending code:
ready
events.js:141
throw er; // Unhandled 'error' event
^
Error: send EADDRNOTAVAIL 192.168.0.7:9999
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at SendWrap.afterSend [as oncomplete] (dgram.js:345:11)
The issue is that the osc.UDPPort that you are using to send OSC messages has its localAddress bound to the loopback address, which is limited to connections within your local computer. As a result, your sender can't find your receiver.
The solution is to bind your sender's localAddress to an appropriate network interface. If your 192.168.0.5 IP address is stable and you don't need to worry about it changing when you connect your laptops to another network (say, for a gig or a gallery installation), then you can just use that. Otherwise, you might want to use an mDNS name ("foo.local") or the "all interfaces" address, 0.0.0.0.
This change to your "Sender code" worked for me when I tried it on my network:
var osc = require("osc");
var udp = new osc.UDPPort({
localAddress: "0.0.0.0", // Totally does matter here :)
localPort: 5000,
remoteAddress: "192.168.0.7", // the other laptop
remotePort: 9999 // the port to send to
});
udp.open();
udp.on("ready", function () {
console.log("ready");
setInterval(function () {
udp.send({
address: "/sending/every/second",
args: [1, 2, 3]
})
}, 1000);
});
As a side note, osc.js's behaviour does differ from a regular Node.js UDP socket, since if the local address is omitted Node will default to 0.0.0.0. An osc.UDPPort, however, will always bind to 127.0.0.1 if localAddress is omitted (which seemed a little safer to me when originally implementing osc.js, but I can see how it might be confusing).
This issue is also discussed on the osc.js issue tracker, and I will update the documentation to prevent the kind of confusion you encountered here. Best of luck with your project!

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