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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -