Skip to content

Instantly share code, notes, and snippets.

@sanketmaru
Last active July 20, 2016 12:06
Show Gist options
  • Save sanketmaru/019d754487c414d36996 to your computer and use it in GitHub Desktop.
Save sanketmaru/019d754487c414d36996 to your computer and use it in GitHub Desktop.
promise-sync-example
Promise.map(emailParams,function(emailParam) {
logger.info('sending email to sendmail for %j', emailParam, {});
var host = "www.example.com/";
var html = jadeS.renderFile(template, {
farms: emailParam.farms,
headerImage: "image",
heading: emailParam.heading,
fieldFocusUrl: "someurl",
host: host
});
return {
from: configure.fromEmailAddress,
to: emailParam.email_id,
subject: 'Some subject',
html: html
};
}).reduce(function(previousPromise, sendArgs) {
return smtp.sendMail(sendArgs);
}, Promise.attempt(_.constant(true))).caught(function(e) {
logger.error('some exceptions has been found %j', e, {});
}).lastly(function() {
logger.info("Completed the job");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment