Hi,
We use crowd for user directory. And using scriptrunner we automate the users to be inactive if they haven't logged in last 90 days. So when the user turns to inactive is it possible to send them automated email notification that their account is inactive?
Hi Sarath,
So we use something similar. Below there are two functions, the one that sends the email I think is what you are looking for.
// deactivate the given user
def deactivateUser(ApplicationUser user) { def userService = ComponentAccessor.getComponent(UserService) def updateUser = userService.newUserBuilder(user).active(false).build() def updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) log.info "${updateUser.name} deactivated" sendEmail(user.emailAddress) } else { log.error "Update of ${user.name} failed. ${updateUserValidationResult.getErrorCollection()}" } }
// send an email to the given address def sendEmail(String emailAddress) { SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer() if (mailServer) { Email email = new Email(emailAddress) email.setSubject("User Deactivated") email.setBody("You became inactive, please send us an email to make you active again, or something similar") mailServer.send(email) log.debug("Mail sent") } else { log.warn("There was an issue with the mail Server") } }
Hope that helps
kind regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.