<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Auto-generation of email with username and random password on creation of new user in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287676#M240806</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have created a class NewUserEmail.java to auto generate an email with username and password while creating a new user. I am able to create the password but whenever I am trying to log in with that password, its not logging in. I am not able to generate my mail. Please guide me and let me know what is wrong with my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import java.util.HashMap;&lt;BR /&gt;import java.util.Map;&lt;BR /&gt;import java.util.Set;&lt;BR /&gt;import javax.mail.MessagingException;&lt;BR /&gt;import javax.mail.internet.MimeMessage;&lt;BR /&gt;import org.alfresco.error.AlfrescoRuntimeException;&lt;BR /&gt;import org.alfresco.model.ContentModel;&lt;BR /&gt;import org.alfresco.repo.jscript.ClasspathScriptLocation;&lt;BR /&gt;import org.alfresco.repo.node.NodeServicePolicies;&lt;BR /&gt;import org.alfresco.repo.policy.JavaBehaviour;&lt;BR /&gt;import org.alfresco.repo.policy.PolicyComponent;&lt;BR /&gt;import org.alfresco.repo.security.authentication.AuthenticationUtil;&lt;BR /&gt;import org.alfresco.service.ServiceRegistry;&lt;BR /&gt;import org.alfresco.service.cmr.repository.ChildAssociationRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeService;&lt;BR /&gt;import org.alfresco.service.cmr.security.PersonService;&lt;BR /&gt;import org.alfresco.service.namespace.NamespaceService;&lt;BR /&gt;import org.alfresco.service.namespace.QName;&lt;BR /&gt;import org.apache.log4j.Logger;&lt;BR /&gt;import org.springframework.mail.javamail.MimeMessageHelper;&lt;BR /&gt;import org.springframework.mail.javamail.MimeMessagePreparator;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public class NewUserEmail implements NodeServicePolicies.OnCreateNodePolicy {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; private Logger logger = Logger.getLogger(NewUserEmail.class);&lt;BR /&gt; &lt;BR /&gt; private PolicyComponent policyComponent;&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; private NodeService nodeService;&lt;BR /&gt; &lt;BR /&gt; private PersonService personService;&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; private ServiceRegistry serviceRegistry;&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; protected String userName = null;&lt;BR /&gt; &lt;BR /&gt; protected String password = null;&lt;BR /&gt; protected String email = null;&lt;/P&gt;&lt;P&gt;protected String subject = null;&lt;BR /&gt; &lt;BR /&gt; protected String body = null;&lt;BR /&gt; &lt;BR /&gt; private static final String NEW_USER_EMAIL_TEMPLATE = "alfresco/module/demoact1-repo/template/new_user_email.ftl";&lt;BR /&gt; &lt;BR /&gt;&lt;SPAN&gt; private static final String EMAIL_FROM = "&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:no-reply@eisenvault.com" rel="nofollow noopener noreferrer"&gt;no-reply@eisenvault.com&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;&lt;BR /&gt; &lt;BR /&gt; public void init() &lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;this.email = "";&lt;BR /&gt; this.userName = "";&lt;BR /&gt; this.password = "";&lt;BR /&gt; this.subject = "New User Alfresco";&lt;BR /&gt; this.body = "";&lt;BR /&gt; &lt;BR /&gt; this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI,"onCreateNode"), ContentModel.TYPE_PERSON, new JavaBehaviour(this,"ReportUser", org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.EVERY_EVENT)); &lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; public void onCreateNode(ChildAssociationRef childAssocRef)&lt;BR /&gt; {&lt;BR /&gt; if (logger.isInfoEnabled()) logger.info(" NewUserEmail Node create policy fired");&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; public void setNodeService(NodeService nodeService)&lt;BR /&gt; {&lt;BR /&gt; this.nodeService = nodeService;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public void setPolicyComponent(PolicyComponent policyComponent) { &lt;BR /&gt; this.policyComponent = policyComponent;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; public void setServiceRegistry(ServiceRegistry serviceRegistry) {&lt;BR /&gt; this.serviceRegistry = serviceRegistry;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; public String getSubject()&lt;BR /&gt; {&lt;BR /&gt; return this.subject;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; public String getBody()&lt;BR /&gt; {&lt;BR /&gt; return this.body;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; public String getEmail()&lt;BR /&gt; {&lt;BR /&gt; return this.email;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public String getUserName()&lt;BR /&gt; {&lt;BR /&gt; return this.userName;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public String getPassword() {&lt;BR /&gt; return password;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void setPassword(String password) {&lt;BR /&gt; this.password = password;&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; public void ReportUser(ChildAssociationRef childAssocRef) &lt;BR /&gt; {&lt;BR /&gt; NodeRef personRef = childAssocRef.getChildRef();&lt;BR /&gt; &lt;BR /&gt; this.userName = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);&lt;BR /&gt; this.email = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_EMAIL); &lt;BR /&gt; sendEmail();&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; public void sendEmail() throws AlfrescoRuntimeException &lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; Map&amp;lt;String, Object&amp;gt; templateModel = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt; &lt;BR /&gt; if (getEmail() != null &amp;amp;&amp;amp; getEmail() != "") &lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; Set&amp;lt;NodeRef&amp;gt; result = serviceRegistry.getPersonService().getPeopleFilteredByProperty(ContentModel.PROP_EMAIL,getEmail(),1);&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; if (result.size() == 1) &lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; changePassword(getUserName());&lt;BR /&gt; &lt;BR /&gt; ClasspathScriptLocation location = new ClasspathScriptLocation(NEW_USER_EMAIL_TEMPLATE);&lt;BR /&gt; &lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; if(location.getInputStream() != null) // Check that there is a template&lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; templateModel.put("userName", getUserName()); &lt;BR /&gt; templateModel.put("password",getPassword());&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; this.body = serviceRegistry.getTemplateService().processTemplate("freemarker", NEW_USER_EMAIL_TEMPLATE, templateModel);&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; catch(AlfrescoRuntimeException e) // If template isn't found, email is constructed "manually"&lt;BR /&gt; {&lt;BR /&gt; logger.error("Email Template not found " + NEW_USER_EMAIL_TEMPLATE );&lt;BR /&gt; &lt;BR /&gt; this.body = "&amp;lt;html&amp;gt; &amp;lt;body&amp;gt; &amp;lt;p&amp;gt; A new User has been created.&amp;lt;/p&amp;gt;" +&lt;BR /&gt; "&amp;lt;p&amp;gt;Hello, &amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Your username is " +getUserName() + " and your " +&lt;BR /&gt; "password is " + getPassword() + "&amp;lt;/p&amp;gt; " +&lt;BR /&gt; "&amp;lt;p&amp;gt;We strongly advise you to change your password when you log in for the first time.&amp;lt;/p&amp;gt;" +&lt;BR /&gt; "Regards&amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;";&lt;BR /&gt; //send();&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; protected void send() &lt;BR /&gt; {&lt;BR /&gt; MimeMessagePreparator mailPreparer = new MimeMessagePreparator() &lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;public void prepare(MimeMessage mimeMessage) throws MessagingException &lt;BR /&gt; {&lt;BR /&gt; MimeMessageHelper message = new MimeMessageHelper(mimeMessage);&lt;BR /&gt; message.setTo(getEmail());&lt;BR /&gt; message.setSubject(getSubject());&lt;BR /&gt; message.setText(getBody(),true);&lt;BR /&gt; message.setFrom(EMAIL_FROM);&lt;BR /&gt; }&lt;BR /&gt; };&lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public void changePassword(String password) &lt;BR /&gt; {&lt;BR /&gt; AuthenticationUtil.setRunAsUserSystem();&lt;BR /&gt; Set&amp;lt;NodeRef&amp;gt; result = serviceRegistry.getPersonService().getPeopleFilteredByProperty(ContentModel.PROP_EMAIL,getEmail(),1);&lt;BR /&gt; &lt;BR /&gt; if (result.size() == 1) &lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; Object[] userNodeRefs = result.toArray();&lt;BR /&gt; NodeRef userNodeRef = (NodeRef) userNodeRefs[0];&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; String username = (String) serviceRegistry.getNodeService().getProperty(userNodeRef,ContentModel.PROP_USERNAME);&lt;BR /&gt; // Generate random password&lt;BR /&gt; String newPassword = Password.generatePassword();&lt;BR /&gt; &lt;BR /&gt; char[] cadChars = new char[newPassword.length()];&lt;BR /&gt; &lt;BR /&gt; for (int i=0; i&amp;lt;newPassword.length(); i++) &lt;BR /&gt; {&lt;BR /&gt; cadChars[i] = newPassword.charAt(i);&lt;BR /&gt; }&lt;BR /&gt; serviceRegistry.getAuthenticationService().setAuthentication(username, newPassword.toCharArray());&lt;BR /&gt; &lt;BR /&gt; setPassword(newPassword);&lt;BR /&gt; &lt;BR /&gt; System.out.println("Password is :" + newPassword);&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Nov 2016 06:33:03 GMT</pubDate>
    <dc:creator>anky_p</dc:creator>
    <dc:date>2016-11-16T06:33:03Z</dc:date>
    <item>
      <title>Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287676#M240806</link>
      <description>I have created a class NewUserEmail.java to auto generate an email with username and password while creating a new user. I am able to create the password but whenever I am trying to log in with that password, its not logging in. I am not able to generate my mail. Please guide me and let me know what</description>
      <pubDate>Wed, 16 Nov 2016 06:33:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287676#M240806</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T06:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287677#M240807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have you tried to use&amp;nbsp;&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.TRANSACTION_COMMIT instead of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.EVERY_EVENT&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 06:55:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287677#M240807</guid>
      <dc:creator>kaynezhang</dc:creator>
      <dc:date>2016-11-16T06:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287678#M240808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes earlier I did that was not able to create user from UI. So changed to EVERY_EVENT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 07:01:06 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287678#M240808</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T07:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287679#M240809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think maybe you should execute your code atfer the transaction event commit&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can refer to&amp;nbsp;&lt;A class="link-titled" href="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" title="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" rel="nofollow noopener noreferrer"&gt;https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 08:47:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287679#M240809</guid>
      <dc:creator>kaynezhang</dc:creator>
      <dc:date>2016-11-16T08:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287680#M240810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tried...not working&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 11:04:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287680#M240810</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T11:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287681#M240811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got the answer:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import org.alfresco.error.AlfrescoRuntimeException;&lt;BR /&gt;import org.alfresco.model.ContentModel;&lt;BR /&gt;import org.alfresco.repo.action.executer.MailActionExecuter;&lt;BR /&gt;import org.alfresco.repo.node.NodeServicePolicies;&lt;BR /&gt;import org.alfresco.repo.policy.JavaBehaviour;&lt;BR /&gt;import org.alfresco.repo.policy.PolicyComponent;&lt;BR /&gt;import org.alfresco.repo.security.authentication.AuthenticationUtil;&lt;BR /&gt;import org.alfresco.service.ServiceRegistry;&lt;BR /&gt;import org.alfresco.service.cmr.action.Action;&lt;BR /&gt;import org.alfresco.service.cmr.action.ActionService;&lt;BR /&gt;import org.alfresco.service.cmr.repository.ChildAssociationRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeService;&lt;BR /&gt;import org.alfresco.service.namespace.NamespaceService;&lt;BR /&gt;import org.alfresco.service.namespace.QName;&lt;BR /&gt;import org.apache.log4j.Logger;&lt;BR /&gt;import org.springframework.util.StringUtils;&lt;/P&gt;&lt;P&gt;import java.io.Serializable;&lt;BR /&gt;import java.util.HashMap;&lt;BR /&gt;import java.util.Map;&lt;BR /&gt;import java.util.UUID;&lt;/P&gt;&lt;P&gt;public class NewUserEmail implements NodeServicePolicies.OnCreateNodePolicy {&lt;/P&gt;&lt;P&gt;private Logger logger = Logger.getLogger(NewUserEmail.class);&lt;BR /&gt; private PolicyComponent policyComponent;&lt;BR /&gt; private NodeService nodeService;&lt;BR /&gt; private ServiceRegistry serviceRegistry;&lt;/P&gt;&lt;P&gt;private static final String NEW_USER_EMAIL_TEMPLATE = "alfresco/module/demoact1-repo/template/new_user_email.ftl";&lt;BR /&gt;&lt;SPAN&gt; private static final String EMAIL_FROM = "&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:no-reply@eisenvault.com" rel="nofollow noopener noreferrer"&gt;no-reply@eisenvault.com&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;&lt;BR /&gt; private static final String EMAIL_SUBJECT = "New User Alfresco";&lt;/P&gt;&lt;P&gt;public void setNodeService(NodeService nodeService) {&lt;BR /&gt; this.nodeService = nodeService;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void setPolicyComponent(PolicyComponent policyComponent) {&lt;BR /&gt; this.policyComponent = policyComponent;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void setServiceRegistry(ServiceRegistry serviceRegistry) {&lt;BR /&gt; this.serviceRegistry = serviceRegistry;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void init() {&lt;BR /&gt; this.policyComponent.bindClassBehaviour(&lt;BR /&gt; QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),&lt;BR /&gt; ContentModel.TYPE_PERSON,&lt;BR /&gt; new JavaBehaviour(this, "ReportUser", org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.EVERY_EVENT)&lt;BR /&gt; );&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void onCreateNode(ChildAssociationRef childAssocRef) {&lt;BR /&gt; reportUser(childAssocRef);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void reportUser(ChildAssociationRef childAssocRef) {&lt;BR /&gt; NodeRef personRef = childAssocRef.getChildRef();&lt;BR /&gt; String username = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);&lt;BR /&gt; if (StringUtils.isEmpty(username)) {&lt;BR /&gt; throw new AlfrescoRuntimeException("Cannot get username, ref: " + childAssocRef);&lt;BR /&gt; }&lt;BR /&gt; String email = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_EMAIL);&lt;BR /&gt; if (StringUtils.isEmpty(email)) {&lt;BR /&gt; throw new AlfrescoRuntimeException("Cannot get email, username: " + username + ", ref: " + childAssocRef);&lt;BR /&gt; }&lt;BR /&gt; String newPassword = generateRandomPassword();&lt;BR /&gt; changePassword(username, newPassword);&lt;BR /&gt; sendEmail(username, newPassword, email);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void sendEmail(String username, String newPassword, String recipient) {&lt;BR /&gt; ActionService actionService = serviceRegistry.getActionService();&lt;BR /&gt; Action ma = actionService.createAction(MailActionExecuter.NAME);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_SUBJECT, EMAIL_SUBJECT);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_FROM, EMAIL_FROM);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TO, recipient);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, NEW_USER_EMAIL_TEMPLATE);&lt;BR /&gt; Map&amp;lt;String, Serializable&amp;gt; templateModel = new HashMap&amp;lt;&amp;gt;();&lt;BR /&gt; templateModel.put("userName", username);&lt;BR /&gt; templateModel.put("password", newPassword);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) templateModel);&lt;BR /&gt; actionService.executeAction(ma, null);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void changePassword(final String username, final String newPassword) {&lt;BR /&gt; // run this as an Admin user, he can change password without knowing the original one!&lt;BR /&gt; AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork&amp;lt;Void&amp;gt;() {&lt;BR /&gt; public Void doWork() throws Exception {&lt;BR /&gt; serviceRegistry.getAuthenticationService().setAuthentication(username, newPassword.toCharArray());&lt;BR /&gt; logger.info("User '" + username + "' password has been changed");&lt;BR /&gt; return null;&lt;BR /&gt; }&lt;BR /&gt; }, AuthenticationUtil.getSystemUserName());&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private String generateRandomPassword() {&lt;BR /&gt; return UUID.randomUUID().toString();&lt;BR /&gt; //or return new BigInteger(130, new SecureRandom()).toString(32);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Nov 2016 07:59:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287681#M240811</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-17T07:59:27Z</dc:date>
    </item>
  </channel>
</rss>

