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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -