Skip to content

Instantly share code, notes, and snippets.

@hinklefoxmail
Created September 3, 2017 00:22
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 hinklefoxmail/bdc33e11da3335c8d22abeb3236b5a8d to your computer and use it in GitHub Desktop.
Save hinklefoxmail/bdc33e11da3335c8d22abeb3236b5a8d to your computer and use it in GitHub Desktop.
Auto Password Reset Gmail
function resetPassword() {
var ss = SpreadsheetApp.getActive();
var cell = ss.getSheetByName('counter').getRange(1, 1)
var counter = cell.getValue();
cell.setValue(counter+1);
var data = ss.getSheetByName('Emails').getDataRange().getValues()
if (counter % 6 === 0){
for (var i = 0; i < data.length; i++){
var email = data[i][0];
Logger.log(email);
try{
var user = AdminDirectory.Users.get(email);
user.changePasswordAtNextLogin = true;
var response = AdminDirectory.Users.update(user, email);
Logger.log('success');
}
catch(e){
Logger.log('fail');
Logger.log(e);
}
}
} else {
Logger.log(counter)
}
}
function emailReminder(){
var ss = SpreadsheetApp.getActive();
var cell = ss.getSheetByName('counter').getRange(1, 1)
var counter = cell.getValue();
var data = ss.getSheetByName('Emails').getDataRange().getValues()
if (counter % 6 === 0){
for (var i = 0; i < data.length; i++){
var email = data[i][0];
Logger.log(email);
MailApp.sendEmail(email, 'Password Reset on Monday', 'Just a reminder that on Monday you will need to change your Gmail password. The system will automatically ask you to do this. No action is currently required by you.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment