Skip to content

Instantly share code, notes, and snippets.

@simong
Created March 19, 2015 12:13
Show Gist options
  • Select an option

  • Save simong/819a39f4c3d56e01e9f4 to your computer and use it in GitHub Desktop.

Select an option

Save simong/819a39f4c3d56e01e9f4 to your computer and use it in GitHub Desktop.
var mailUsersFromTenant = function(tenantAlias, callback) {
// Gets called for every 50 principals
var handlePrincipals = function(principals, next) {
// The `principals` set can contain groups, we just need the users
var users = _.filter(principals, function(principal) {
return PrincipalsUtil.isUser(principal.principalId);
});
// Send out the emails and move on to the next set of users when done
mailUsers(users, next);
};
PrincipalsDAO.iterateAll(['principalId', 'tenantAlias', 'displayName', 'email'], 50, handlePrincipals, function(err) {
if (err) {
...
}
log().info('All done');
return callback();
});
};
var mailUsers = function(users, callback) {
if (_.isEmpty(users)) {
return callback();
}
var user = users.pop();
var data = { /* data that's needed in the email template */ };
EmailAPI.sendEmail('oae-my-module', 'name-of-my-mail-template', user, data, {}, function(err) {
if (err) {
...
}
mailUsers(users, callback);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment