5

i'm trying to use the emailjs (https://github.com/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.com", 
       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); });
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) Commented Jun 2, 2015 at 14:38
  • See here: github.com/eleith/… are you sure you need ssl, and not tls? Commented Jun 2, 2015 at 14:43
  • This code of the link not works too. Commented Jun 2, 2015 at 14:49

5 Answers 5

4

I 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.com',
  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.com instead of smtp-mail.live.com

Note: The account ([email protected]) used is a valid one I just created for testing purposes.

Sign up to request clarification or add additional context in comments.

Comments

2

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.com/u/2/lesssecureapps?pageId=none

After:

var email   = require("emailjs");
var server  = email.server.connect({
   user:    "[email protected]", 
   password:"YOUR_PASSWORD", 
   host:    "smtp.gmail.com",
   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

1 Comment

Hello I have activated the use less secure app but I am facing an error like ERROR TypeError: Class extends value undefined is not a constructor or null at Object../node_modules/emailjs/smtp/message.js at __webpack_require__ (bootstrap:79)
1

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.com",
   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);
    });

Comments

0

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.com",
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 .

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.