<?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 Re: Envio Email Nuevo Usuario in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159279#M113318</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Me aparece un error, 404 _"index of"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Jul 2013 17:30:01 GMT</pubDate>
    <dc:creator>vilatore</dc:creator>
    <dc:date>2013-07-01T17:30:01Z</dc:date>
    <item>
      <title>Envio Email Nuevo Usuario</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159277#M113316</link>
      <description>Hola buenas,&amp;nbsp; aquí va el código para Enviar un Email con los datos de acceso a un nuevo usuario automáticamente. Espero que os sirva de algo. Seguramente hay algún fallo,y se podría mejorar, cualquier aporte será bienvenido.Software necesario. Alfresco-community y alfresco-community-sdk tienen que c</description>
      <pubDate>Fri, 13 May 2011 08:44:40 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159277#M113316</guid>
      <dc:creator>dfernandezgonza</dc:creator>
      <dc:date>2011-05-13T08:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Envio Email Nuevo Usuario</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159278#M113317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hola dfernandezgonzalez, gracias por la aportación, seguro que tiene utilidad para muchos usuarios.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Si lo llegas a presentar al concurso de hace un mes seguro que algo te hubieses llevado &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://connect.hyland.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Saludos!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 May 2011 10:06:29 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159278#M113317</guid>
      <dc:creator>venzia</dc:creator>
      <dc:date>2011-05-16T10:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Envio Email Nuevo Usuario</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159279#M113318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Me aparece un error, 404 _"index of"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jul 2013 17:30:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159279#M113318</guid>
      <dc:creator>vilatore</dc:creator>
      <dc:date>2013-07-01T17:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Envio Email Nuevo Usuario</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159280#M113319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #212121; background-color: #ffffff; font-size: 16px;"&gt;He creado una clase NewUserEmail.java para generar automáticamente un correo electrónico con nombre de usuario y contraseña al crear un nuevo usuario. Soy capaz de crear la contraseña, pero cuando intento iniciar sesión con esa contraseña, no se está ingresando. No puedo generar mi correo.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&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 style="color: #727174; border: 0px; font-size: 15px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;public class NewUserEmail implements NodeServicePolicies.OnCreateNodePolicy {&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;&lt;BR /&gt;private Logger logger = Logger.getLogger(NewUserEmail.class);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private PolicyComponent policyComponent;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;private NodeService nodeService;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private PersonService personService;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;private ServiceRegistry serviceRegistry;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;protected String userName = null;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;protected String password = null;&lt;BR /&gt;protected String email = null;&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;protected String subject = null;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;protected String body = null;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;private static final String NEW_USER_EMAIL_TEMPLATE = "alfresco/module/demoact1-repo/template/new_user_email.ftl";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="border: 0px; font-weight: inherit; font-size: 15px;"&gt;private static final String EMAIL_FROM = "&lt;/SPAN&gt;&lt;A href="mailto:no-reply@eisenvault.com" style="color: #1e88e5; background-color: transparent; border: 0px; font-weight: inherit; font-size: 15px; padding: 1px 0px 1px calc(12px + 0.35ex);" rel="nofollow noopener noreferrer"&gt;no-reply@eisenvault.com&lt;/A&gt;&lt;SPAN style="border: 0px; font-weight: inherit; font-size: 15px;"&gt;";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public void init() &lt;BR /&gt;{&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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 style="color: #727174; border: 0px; font-size: 15px;"&gt;&lt;BR /&gt;public void setPolicyComponent(PolicyComponent policyComponent) { &lt;BR /&gt;this.policyComponent = policyComponent;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;public void setServiceRegistry(ServiceRegistry serviceRegistry) {&lt;BR /&gt;this.serviceRegistry = serviceRegistry;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public String getSubject()&lt;BR /&gt;{&lt;BR /&gt;return this.subject;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public String getBody()&lt;BR /&gt;{&lt;BR /&gt;return this.body;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;public String getEmail()&lt;BR /&gt;{&lt;BR /&gt;return this.email;&lt;BR /&gt;}&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;&lt;BR /&gt;public String getUserName()&lt;BR /&gt;{&lt;BR /&gt;return this.userName;&lt;BR /&gt;}&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;&lt;BR /&gt;public String getPassword() {&lt;BR /&gt;return password;&lt;BR /&gt;}&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&gt;public void setPassword(String password) {&lt;BR /&gt;this.password = password;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;public void ReportUser(ChildAssociationRef childAssocRef) &lt;BR /&gt;{&lt;BR /&gt;NodeRef personRef = childAssocRef.getChildRef();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;public void sendEmail() throws AlfrescoRuntimeException &lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Map&amp;lt;String, Object&amp;gt; templateModel = new HashMap&amp;lt;String, Object&amp;gt;();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (getEmail() != null &amp;amp;&amp;amp; getEmail() != "") &lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Set&amp;lt;NodeRef&amp;gt; result = serviceRegistry.getPersonService().getPeopleFilteredByProperty(ContentModel.PROP_EMAIL,getEmail(),1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (result.size() == 1) &lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;changePassword(getUserName());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ClasspathScriptLocation location = new ClasspathScriptLocation(NEW_USER_EMAIL_TEMPLATE);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;if(location.getInputStream() != null) // Check that there is a template&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;templateModel.put("userName", getUserName()); &lt;BR /&gt;templateModel.put("password",getPassword());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;this.body = serviceRegistry.getTemplateService().processTemplate("freemarker", NEW_USER_EMAIL_TEMPLATE, templateModel);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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 style="color: #727174; border: 0px; font-size: 15px;"&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="color: #727174; border: 0px; font-size: 15px;"&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (result.size() == 1) &lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Object[] userNodeRefs = result.toArray();&lt;BR /&gt;NodeRef userNodeRef = (NodeRef) userNodeRefs[0];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;char[] cadChars = new char[newPassword.length()];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;setPassword(newPassword);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;System.out.println("Password is :" + newPassword);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 06:53:35 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/envio-email-nuevo-usuario/m-p/159280#M113319</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T06:53:35Z</dc:date>
    </item>
  </channel>
</rss>

