I am trying to use gmail smtp using node_mailer
. I get following error on my nodejs logs (using nodester). Here is my code:
var email = require('mailer');
email.send({
host : "smtp.gmail.com",
port : "465",
ssl : true,
domain : "domain.com",
to : "emailId@gmail.com",
from : "email@gmail.com",
subject : "You have been registered",
body: "<B>Hello! This is a test of the node_mailer.</B>",
authentication : "login", // auth login is supported; anything else is no auth
username : /* username */,
password : /* password */
},
function(err, result){
if(err){ self.now.error(err); console.log(err); return;}
else this.now.successfullySent(result);
});
I am not getting any error in the stack but email is not getting delivered.
@work4liberty and @David Ellis. Thanks for both of yours inputs but it seems that the problem was not with my server code, I was sending incorrect value in emailId from my client-side javascript. Nodemailer
did help me debug the issue with correct text in error.
A couple things:
Full Disclosure: I contributed the Amazon SES functionality to Nodemailer (though a recent rewrite of the underlying architecture from 0.1.x to 0.3.x means I don't show up on git blame
, anymore).
EDIT: I took a closer look at your code. Assuming you don't have the typos in your actual code, I suspect the following line is the culprit: this.now.successfullySent(result);
Basically, the callback function's this
is not what you think it is. You'll want to cache the this
object in its scope by assigning it to a variable like self
. (Assuming we're not dealing with a problem in the underlying library.)
Replacing the xxx with my password this code works for me copy and paste that and see how it works if it dose not work for you maybe it is just lag witch happens from time to time or (I hope not) your ip or something in your msg make gmail think it was spam
var email = require('mailer');
email.send({
host : "smtp.gmail.com",
port : "465",
ssl : true,
domain : "domain.com",
to : "work4liberty@gmail.com",
from : "work4liberty@gmail.com",
subject : "You have been registered",
body: "<B>Hello! This is a test of the node_mailer.</B>",
authentication : "login", // auth login is supported; anything else $
username : 'work4liberty@gmail.com',
password : 'xxx'
},
function(err, result){
if(err){ self.now.error(err); console.log(err); return;}
else console.log('looks good')
});