catch error on try nodemailer.createTransport #115

alvarolm opened this Issue Oct 29, 2012 · 1 comment


None yet
2 participants

sorry for my noob'nes )

lets say i have this>

smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: "", pass: "xxxxxx" }});

somethimes when I try to auth on gmail smtp services my password could be wrong or anything and with "winston" can see and inspect the error(s) >

logger.on('logging', function (transport, level, msg, meta) {
// GMAIL:AuthError: Invalid login - 535-5.7.1 Username and Password not accepted. - // n=0
if ( {
    if (("535-5.7.1")!=-1) {smtpTransport.close(); global.alertm_fatal = true; logger.error('alerta por e-mail cancelada: ' + msg + transport)}

thats ok, but i cant find a way to catch if the process is succesful or not, only after happens, I have tried this in various ways >

try {var smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: "", pass: "xxxxxxxxx" }});} catch (error) { console.log("WTF");}

and just dont work, someone can help me ? :)

it needs a callback !!!?


andris9 commented Oct 29, 2012


try...catch block does not work with createTransport as createTransport doesn't "do" really anything but storing the credentials for later usage. It is only after trying to send the first e-mail when the connection is actually opened and it is checked if the credentials are actually valid. See return callback for details.

@andris9 andris9 closed this Oct 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment