javascript - Promisify Nodemailer with bluebird? -


the nodemailer author has made clear he's not supporting promises. thought i'd try hand @ using bluebird, attempt @ doesn't seem catch errors nodemailer throws:

var nodemailer = require('nodemailer'); var promise = require('bluebird');  // build transport promises var transport = promise.promisifyall( nodemailer.createtransport({...}) );  module.exports = {     doit = function() {         // use bluebird async         return transport.sendmailasync({...});     } } 

then call doing:

doit().then(function() {     console.log("success!"); }).catch(function(err) {     console.log("there has been error"); }); 

however, when providing invalid email, see this:

unhandled rejection error: can't send mail - recipients rejected 

so, nodemailer error isn't being caught bluebird promise. have done wrong?

can't what's wrong code top of head. i've ran similar problems promisification , decided it's easier promisify problem cases manually instead. it's not elegant solution, it's solution.

var transport = nodemailer.createtransport({...});  module.exports = {     doit: function() {         return new promise(function (res, rej) {            transport.sendmail({...}, function cb(err, data) {                 if(err) rej(err)                 else res(data)             });         });     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -