问题
How can we auto-generate a mail with the new user's password as soon as we click on the create user button in Alfresco New User page. Do we need to create any webscript or action which can redirect to create user action and a corresponding mail will be generated automatically. Please let me know how to create the link between Create User button and the mail to the new user.
回答1:
Ultimately any thing in alfresco is node. User is also one type of node in alfresco.As per my perspective the best solution is to create a behavior and send an email.
Below is detail for implementation of behaviour in alfresco.
https://www.alfresco.com/blogs/lcabaceira/2015/04/07/alfresco-behaviours-and-policies/
This is one link for behaviour in alfresco.You will find multiple link for behaviour in alfresco.
回答2:
Create the new rule:
- on
Repository > User Homes
folder - when:
Items are created or enter this folder
perform action:
Execute script
:if (document.isContainer && document.displayPath == "/Company Home/User Homes") { var owner = document.properties["cm:owner"]; var pNode = people.getPerson(owner); if (pNode!=null && pNode.exists()){ var userName = pNode.properties.userName; var email = pNode.properties.email; var randPassword = Math.random().toString(36).substr(2, 30)+"-"+(Date.now()); people.setPassword(userName, randPassword); logger.debug("Invitation mail: User "+userName+" password has been changed."); var mail = actions.create("mail"); //mail.parameters.from = "noreply@customdomain"; mail.parameters.to = email; mail.parameters.subject = "Welcome to the jungle, login: "+userName+", password: "+randPassword; mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Invite Email Templates/invite_user_email.ftl"); var templateModel = new Array(); templateModel['newPassword'] = randPassword; // use ${newPassword} expression inside template mail.parameters.template_model = templateModel; mail.executeAsynchronously(document); logger.debug("Invitation mail has been sent to "+email); } else { logger.warn("Invitation mail: User not found: "+owner); } } else { logger.warn("Invitation mail: Document "+document.name+" / "+document.nodeRef+" is not a user home folder."); }
You can use https://papercut.codeplex.com/ to test it, Alfresco configuration:
# smtp settings
mail.host=localhost
mail.port=25
mail.protocol=smtp
mail.smtp.auth=false
# mail.smtp.timeout=30000
# mail.smtp.debug=true
来源:https://stackoverflow.com/questions/40150331/how-to-auto-generate-a-mail-with-the-password-created-after-clicking-on-create