Created
March 19, 2015 12:13
-
-
Save simong/819a39f4c3d56e01e9f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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