i'm trying to use the emailjs () for send emails with nodejs, but, it gives me an error: { [Error: timedout while connecting to smtp server] code: 4, smtp: undefined }
I'm trying to use hotmail, but I can use other, I only want this working. Any idea please?
var email = require("emailjs");
var server = email.server.connect({
user: "[email protected]",
password:"xxxyyyy",
host: "smtp-mail.live",
ssl: true
});
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: "i hope this works",
from: "you <[email protected]>",
to: "someone <[email protected]>",
//cc: "else <[email protected]>",
subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });
i'm trying to use the emailjs (https://github./eleith/emailjs) for send emails with nodejs, but, it gives me an error: { [Error: timedout while connecting to smtp server] code: 4, smtp: undefined }
I'm trying to use hotmail, but I can use other, I only want this working. Any idea please?
var email = require("emailjs");
var server = email.server.connect({
user: "[email protected]",
password:"xxxyyyy",
host: "smtp-mail.live.",
ssl: true
});
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: "i hope this works",
from: "you <[email protected]>",
to: "someone <[email protected]>",
//cc: "else <[email protected]>",
subject: "testing emailjs"
}, function(err, message) { console.log(err || message); });
Share
Improve this question
asked Jun 2, 2015 at 14:29
JMRJMR
7651 gold badge9 silver badges31 bronze badges
3
- The error suggests it is a simple connection information error, or a problem with your network, neither of which we can help much with unless you also provided the server connection information that you were given for the mailserver (without creds of course) – Kevin B Commented Jun 2, 2015 at 14:38
- See here: github./eleith/… are you sure you need ssl, and not tls? – Kevin B Commented Jun 2, 2015 at 14:43
- This code of the link not works too. – JMR Commented Jun 2, 2015 at 14:49
5 Answers
Reset to default 4I tested with the code below (using gmail) and it is working:
var email = require('emailjs');
var server = email.server.connect({
user: '[email protected]',
password: 'stackoverflow',
host: 'smtp.gmail.',
ssl: true
});
server.send({
text: 'Hey howdy',
from: 'NodeJS',
to: 'Wilson <[email protected]>',
cc: '',
subject: 'Greetings'
}, function (err, message) {
console.log(err || message);
});
In my console the output is:
{
attachments: [],
alternative: null,
header: {
'message-id': '<[email protected]>',
date: 'Tue, 02 Jun 2015 10:48:58 -0400',
from: '=?UTF-8?Q?NodeJS?= <>',
to: '=?UTF-8?Q?Wilson?= <[email protected]>',
cc: '',
subject: '=?UTF-8?Q?Greetings?='
},
content: 'text/plain; charset=utf-8',
text: 'Hey howdy'
}
Indeed I have received in my inbox the email message.
I suspect that you should use the host smtp.live. instead of smtp-mail.live.
Note: The account ([email protected]) used is a valid one I just created for testing purposes.
Using Gmail
First: Required activate the use less secure apps at your own risk as indicated in the Gmail documentation. I use an account not very important for my tests:
https://myaccount.google./u/2/lesssecureapps?pageId=none
After:
var email = require("emailjs");
var server = email.server.connect({
user: "[email protected]",
password:"YOUR_PASSWORD",
host: "smtp.gmail.",
ssl: true
});
server.send({
text: "Hello world",
from: "YOUR_NAME <[email protected]>",
to: "FRIEND_NAME <[email protected]>",
subject: "Hello"
}, function(err, message) { console.log(err || message); });
Additional Note: About how set "from" and displayed name in Gmail inbox:
Example 1:
Set "from" with only name.
from: "YOUR_NAME", // Only name
In inbox display <>
YOUR_NAME <> Hello 18:11
Example 2:
Set "from" with name and emial.
from: "YOUR_NAME <[email protected]>", // Name and email
In inbox not display <>
YOUR_NAME Hello 18:11
Make sure you are linking the emailjs files correctly (check var email) or it won't work.
//Email stuff
var email = require("./node_modules/emailjs/email");
var server = email.server.connect({
user: "[email protected]",
password:"INSERTPASSWORDHERE",
host: "smtp.gmail.",
ssl: true
});
//If button is clicked then send email
server.send({
text: 'Hello World! \n\n Regards,\n INSERTNAMEHERE \n',
from: 'Name',
to: 'Name <[email protected]>',
cc: '',
subject: ''
}, function (err, message) {
console.log(err || message);
});
make sure you have installed exact package with same version
npm i [email protected]
and try below code
var email = require("emailjs");
var server = email.server.connect({
user: "[email protected]",
password: "your-password",
host: "smtp.gmail.",
ssl: true
});
server.send(
{
text: "Hey howdy",
from: "NodeJS",
to: "Wilson <[email protected]>",
cc: "",
subject: "Greetings"
},
function(err, message) {
console.log(err || message);
}
);
seems latest version is not working its using es6 exports "[email protected]" but version still works fine . also don't forget to enable less secure setting for email address you are using with password .
I think you can use this version
[email protected]
, For me, this is working in version 2.2.0 where version 3.0 and above will show the error.
npm i [email protected]
here is the example