Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emailjs not working [node js]

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); });
like image 933
JMR Avatar asked Jun 02 '15 14:06

JMR


1 Answers

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.

like image 55
Wilson Avatar answered Oct 04 '22 02:10

Wilson