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

hyperation
Champ on-the-rise
Champ on-the-rise
Hi analyzediz,

Any luck so far?

Thanks
Smiley Happy

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
hi you should do :

 setText("text",true); 

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

I am sending mail using the Java Script code in my process definition. Like this
var mail = actions.create("mail");
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 ";
mail.execute(bpm_package);


So where I need to set that?  setText("text",true);

Pls reply.

Thanks

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
I will provide you with the code today.

pp20218
Champ in-the-making
Champ in-the-making
Thank you.

Waiting for ur reply.

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
hi, i have code for you. hire .


var mail = actions.create("mail2");
mail.parameters.to = "savic.prvoslav[at]gmail.com";
mail.parameters.subject = "Html test";
mail.parameters.from = "savic.prvoslav[at]gmail.com";
mail.parameters.text = "My name is Savić Prvoslav<b> if you see this it is very bold</b>";
mail.parameters.node=document;
mail.execute(document);

I have taken freedom to add send file feature for you, hope this is helpful Smiley Happy

hi savic.prvoslav i followed same code but i not able to send mail, i am writing the above code in the document-actions.js file to send mail when ever a document is opened by any one.

vikram

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

I tried with your code but I have so many issues. this is what I did.

(1)Copied custom-action.jar in /opt/Alfresco/tomcat/webapps/alfresco/WEB-INF/lib location.
(2)changed the review_processdefinition.xml as
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);


only these 2 changes. When I restart the server I am getting error and my server is not starting .Log says as below.

11:04:38,939 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
java.lang.RuntimeException: java.net.BindException: Address already in use
   at org.subethamail.smtp.server.SMTPServer.start(SMTPServer.java:198)
   at org.alfresco.email.server.impl.subetha.SubethaEmailServer.startup(SubethaEmailServer.java:60)
   at org.alfresco.email.server.EmailServer.onBootstrap(EmailServer.java:230)
   at org.springframework.extensions.surf.util.AbstractLifecycleBean.onApplicationEvent(AbstractLifecycleBean.java:56)
   at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
   at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:294)
….


Caused by: java.net.BindException: Address already in use
   at java.net.PlainSocketImpl.socketBind(Native Method)
   at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
   at java.net.ServerSocket.bind(ServerSocket.java:319)
   at org.subethamail.smtp.server.SMTPServer.createServerSocket(SMTPServer.java:304)
   at org.subethamail.smtp.server.SMTPServer.start(SMTPServer.java:194)
   … 42 more


Also In 2nd way I copied that jar file and put custom-action-context.xml inside /opt/Alfresco/tomcat/shared/classes/alfresco/extension Still the same problem.

I created a class CustomMailActionExecuter.java with your code but there are so many errors as below
(a) import org.alfresco.repo.action.executer.TestModeable; is not there where I will find this class?
(b) inside executeImpl() MimeMessagePreparator mailPreparer = new MimeMessagePreparator(ruleAction, actionedUponNodeRef) shows the error the constructor Object() not defined.

Can you help pls?

Thanks

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
ava.lang.RuntimeException: java.net.BindException: Address already in use

this means that you have port 8080( or some port else)  taken Smiley Very Happy, restart your computer if this is local or see what port is taken .