The nodemailer author has made clear he's not supporting promises. I thought I'd try my hand at using bluebird, but my attempt at it doesn't seem to catch any errors that Nodemailer throws:
var nodemailer = require('nodemailer');
var Promise = require('bluebird');
// build the transport with promises
var transport = Promise.promisifyAll( nodemailer.createTransport({...}) );
module.exports = {
doit = function() {
// Use bluebird Async
return transport.sendMailAsync({...});
}
}
Then I call it by doing:
doit().then(function() {
console.log("success!");
}).catch(function(err) {
console.log("There has been an error");
});
However, when providing an invalid email, I see this:
Unhandled rejection Error: Can't send mail - all recipients were rejected
So, the nodemailer error isn't being caught by my bluebird promise. What have I done wrong?
Can't say what's wrong with the code from the top of my head. I've ran into similar problems with promisification and decided it's easier to just promisify the problem cases manually instead. It's not the most elegant solution, but it's a solution.