Skip to content

Instantly share code, notes, and snippets.

@ericf
Last active December 20, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericf/6153024 to your computer and use it in GitHub Desktop.
Save ericf/6153024 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var async = require('async'),
email = require('../lib/email'),
invs = require('../lib/invitations');
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdout.write('Are you sure you want to BLAST OFF EMAILS? (yes/NO): ');
process.stdin.once('data', function (answer) {
answer = answer.toString().trim().toLowerCase();
if (answer === 'yes') {
sendRsvpEmails();
} else {
console.log('Aborting!');
process.exit();
}
});
function sendRsvpEmails() {
console.log('Loading invitations from database...');
invs.loadInvitations(function (err, invitations) {
if (err) { throw err; }
async.eachSeries(invitations, sendEmail, function (err) {
console.log('Done!');
process.exit();
});
});
}
function sendEmail(invitation, callback) {
email.sendRsvpLink(invitation.id, function (err, res, body) {
if (err) {
console.log(err);
} else {
console.log('Sent RSVP link to Invitation: ' + invitation.id + ' recipients.');
}
callback(null);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment