|
| 1 | +var nodemailer = require('nodemailer'), |
| 2 | + mongoose = require('mongoose'), |
| 3 | + config = require('../config/config'), |
| 4 | + mg = require('../config/lib/mongoose'); |
| 5 | + |
| 6 | +var transporter = nodemailer.createTransport(config.mailer.options); |
| 7 | +var link = 'reset link here'; // PUT reset link here |
| 8 | + |
| 9 | +mg.connect(function(db) { |
| 10 | + var User = mongoose.model('User'); |
| 11 | + |
| 12 | + User.find().exec(function(err, users) { |
| 13 | + if (err) { |
| 14 | + throw err; |
| 15 | + } |
| 16 | + |
| 17 | + var email = { |
| 18 | + |
| 19 | + subject: 'Security update' |
| 20 | + }; |
| 21 | + |
| 22 | + for (var i = 0; i < users.length; i++) { |
| 23 | + var text = [ |
| 24 | + 'Dear ' + users[i].displayName, |
| 25 | + '\n', |
| 26 | + 'We have updated our password storage systems to be more secure and more efficient, please click the link below to reset your password so you can login in the future.', |
| 27 | + link, |
| 28 | + '\n', |
| 29 | + 'Thanks,', |
| 30 | + 'The Team' |
| 31 | + ].join('\n'); |
| 32 | + |
| 33 | + email.to = users[i].email; |
| 34 | + email.text = text; |
| 35 | + email.html = text; |
| 36 | + |
| 37 | + transporter.sendMail(email, function(err, info) { |
| 38 | + if (err) { |
| 39 | + console.log('Error: ', err); |
| 40 | + console.log('Could not send email for ', users[i].displayName); |
| 41 | + } else { |
| 42 | + console.log('Sent reset password email for ', users[i].displayName); |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + console.log('Sent all emails'); |
| 48 | + process.exit(0); |
| 49 | + }); |
| 50 | +}); |
0 commit comments