cancel
Showing results for 
Search instead for 
Did you mean: 

Create HTML email using MailAction

analyzediz
Champ in-the-making
Champ in-the-making
Hi all,

I'm currently using Alfresco's MailAction class to send emails based on a scheduled job definition. From my JavaScript I am able to  prepare the message by obtaining a reference to the mailAction object  and setting the desired parameters such as:

mail.parameters.to = "to address";
mail.parameters.subject = "subject";
mail.parameters.from = "from address";

I was able to successfully but If I attempt to send an HTML snippet, it's sending the email body as if it's a plain text email. I see that the underlying MailActionExecuter class uses the MimeMessageHelper to prepare the email that is to be sent. Of note is the setText() call on the MimeMessageHelper which sets the email body. It seems like the MailActionExecuter uses the setText(text) variant of this method and provides no way of invoking the setText(text, boolean) version which would allow one to specify a boolean value indicating that the body text is HTML.

Is there a way of getting around this, short of having to extend the MailActionExecuter? It seems like it would end up being a lot of duplicated code just to get this working.

Am I missing something here? Any pointer would be greatly appreciated.

Thanks.
18 REPLIES 18

pp20218
Champ in-the-making
Champ in-the-making
Hi,

That issue is fixed I had some other  changes. Now when I put the custom-action-context.xml under shared/extension and custom-action.jar under webapps/alfresco/lib I am getting some different kind of error

org.alfresco.service.cmr.workflow.WorkflowException: 09040001 Failed to signal transition {0} from workflow task {1}.
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.endTask(JBPMEngine.java:1809)
   at org.alfresco.repo.workflow.WorkflowServiceImpl.endTask(WorkflowServiceImpl.java:621)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:43)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:135)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy54.endTask(Unknown Source)
   at org.alfresco.web.bean.workflow.StartWorkflowWizard.finishImpl(StartWorkflowWizard.java:233)
   at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.java:118)
   at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.java:115)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:321)
   at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.java:124)
   at org.alfresco.web.bean.wizard.WizardManager.finish(WizardManager.java:593)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
   at javax.faces.component.UICommand.broadcast(UICommand.java:109)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:104)
   at sun.reflect.GeneratedMethodAccessor468.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy200.doFilter(Unknown Source)
   at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.repo.web.filter.beans.NullFilter.doFilter(NullFilter.java:68)
   at sun.reflect.GeneratedMethodAccessor468.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:116)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy200.doFilter(Unknown Source)
   at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.jbpm.graph.def.DelegationException: 09040000 Script expression has not been provided
   at org.jbpm.graph.def.GraphElement.raiseException(GraphElement.java:388)
   at org.jbpm.graph.def.GraphElement.raiseException(GraphElement.java:379)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:301)
   at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:241)
   at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:213)
   at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:196)
   at org.jbpm.graph.def.Transition.take(Transition.java:152)
   at org.jbpm.graph.def.Node.leave(Node.java:479)
   at org.jbpm.graph.node.TaskNode.leave(TaskNode.java:213)
   at org.jbpm.graph.def.Node.leave(Node.java:438)
   at org.jbpm.graph.node.TaskNode.execute(TaskNode.java:194)
   at org.jbpm.graph.def.Node.enter(Node.java:390)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:157)
   at org.jbpm.graph.def.Node$$EnhancerByCGLIB$$2c4150c5.enter(<generated>)
   at org.jbpm.graph.def.Transition.take(Transition.java:167)
   at org.jbpm.graph.def.Node.leave(Node.java:479)
   at org.jbpm.graph.node.StartState.leave(StartState.java:82)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:157)
   at org.jbpm.graph.def.Node$$EnhancerByCGLIB$$2c4150c5.leave(<generated>)
   at org.jbpm.graph.exe.Token.signal(Token.java:223)
   at org.jbpm.graph.exe.Token.signal(Token.java:150)
   at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:490)
   at org.alfresco.repo.workflow.jbpm.WorkflowTaskInstance.end(WorkflowTaskInstance.java:135)
   at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:406)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine$26.doInJbpm(JBPMEngine.java:1783)
   at org.springmodules.workflow.jbpm31.JbpmTemplate$1.doInHibernate(JbpmTemplate.java:87)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
   at org.springmodules.workflow.jbpm31.JbpmTemplate.execute(JbpmTemplate.java:80)
   at org.alfresco.repo.workflow.jbpm.JBPMEngine.endTask(JBPMEngine.java:1758)
   … 71 more
Caused by: org.alfresco.service.cmr.workflow.WorkflowException: 09040000 Script expression has not been provided
   at org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript.execute(AlfrescoJavaScript.java:117)
   at org.jbpm.graph.def.Action.execute(Action.java:129)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:284)
   … 106 more


I need to put both the jar and the XML right or only jar is enough?

Thanks

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
so all you need to to is to add jar file to web-inf/lib and to use script to send mail. that is all.

about other xml file, you do not need this for my feature.

pp20218
Champ in-the-making
Champ in-the-making
Hi,

I tested send mail feature from Alfresco, it is working fine. I invited a user to the space and he received the email.It means send mail is working. Is nt it?

U mean to say I need to put only the jar file under /opt/Alfresco/tomcat/webapps/alfresco/WEB-INF/lib and in the review_processdefinition.xml i used
var mail = actions.create("mail2");
mail.parameters.to = bpm_assignee.properties.email;
mail.parameters.subject = "Review and Approval of Document";
mail.parameters.from = initiator.properties.email;
mail.parameters.text = "Hi <b> if you see this it is very bold</b> ";
mail.parameters.node=document;
mail.execute(bpm_package);
code to send email

What about custom-action-context.xml where u have written

<beans>
     
   

   <bean id="mail2"   class="org.alfresco.sample.CustomMailActionExecuter" parent="action-executer">
      <property name="mailService">
         <ref bean="mailService"></ref>
      </property>
      <property name="templateService">
         <ref bean="templateService"></ref>
      </property>
      <property name="personService">
         <ref bean="personService"></ref>
      </property>
      <property name="authenticationService">
         <ref bean="authenticationService"></ref>
      </property>
      <property name="nodeService">
         <ref bean="nodeService"></ref>
      </property>
      <property name="authorityService">
         <ref bean="authorityService"></ref>
      </property> ……

Do you think this custom-action-context.xml is not required??

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
Smiley Happy
that xml file is in jar you have donloaded. so you just put jar  and do not extract xml file from jar Smiley Happy

gauchoproluanco
Champ in-the-making
Champ in-the-making
Hi Savic,

It could be possible to send an email in html format with the default mail action? Should I use the processTemplate(template) method for this? I mean I have this code:

var mail = actions.create("mail");
mail.parameters.to = args.emailto;
mail.parameters.subject = "";
mail.parameters.from = "gauhoproluanco@alfresco.com";

var template = search.luceneSearch("+PATH:\"/app:company_home/st:sites/cm:ayuntamiento/*\"" + "+@cm\\:name:\"sendEmail.get.html.ftl\"")[0];

var doc = search.luceneSearch("+PATH:\"/app:company_home/st:sites/cm:ayuntamiento/*\"" + "+@cm\\:name:\"solicitud_1021947138697101994.pdf\"")[0];

var result = doc.processTemplate(template);

mail.parameters.text = result;

mail.execute(doc);

It works ok, but instead of getting a e-mail in html format I get plain text.

Another issue is that in the e-mail from I don't get the mail.parameters.from value ("gauhoproluanco@alfresco.com")

Thanks in advance,

Luis

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
You can not send html mails with default alfresco action Smiley Sad .
but you can download it for free and use action that does .

At my blog you can notice that I use mail2 acton in javascript tutorial, that action supports html .
so you need to download my jar file and install it in alfresco then run the javascript with mail2 action name.

gauchoproluanco
Champ in-the-making
Champ in-the-making
Hi Savic,

Really thanks for your reply! I will download your jar and I'm going to try it.

Thanks again,

Luis

chud
Champ in-the-making
Champ in-the-making
If anyone encounters this issue and finds this post it may be worth knowing that at the moment Alfresco will set an email to text/html if the content of the email starts with <html

mrksjs
Champ on-the-rise
Champ on-the-rise
thanks a lot for the info chud! helped me out!