cancel
Showing results for 
Search instead for 
Did you mean: 

How to Use Custom Email Template 4 Sending Email from Share?

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Dear Folks,

I am new to Email Templates. I know Alfresco's default Email Templates are at Company Home/Data Dictionary/Email template space.

Now I want to create custom email template which is nothing but simple FTL file (Which I can do) but the problem or issue I am facing is how to use that template in Alfresco SHARE Webscript (JavaScript) for sending a mail with that email body which is again dynamic as per the template (i.e. Alfresco reads the template and place dynamic values in to that template as per the syntax and sends the mail).

Please help me with sample code or a sample example for using Email Template to send mails from Alfresco Share Site.

Thanks!
-Nirvan
3 REPLIES 3

pawel_rzeszowsk
Champ in-the-making
Champ in-the-making
Hi,
what do you think about the following solution:
1. Create the custom email action which will allow you to pass an email template as parameters. In this acction you will use the Template Service.
2. Use the code like this to process the passed template:
text = templateService.processTemplate("freemarker", templateRef.toString(), model);
3. Create a webscript which you will call from Share, which will call the custom email action.

Best Regards,
Pawel Rzeszowski.

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Dear pawel_rzeszowski,

Thanks a billion for your reply.

Just correct me if I am wrong,From your reply What I understood is I have to write one Java Class and made its entry in ……-context.xml and that class I have to call from share webscript.

The position where I get stuck is , as of now I am sending static mail with document name to the user in my DATA WEBSCRIPT with this code

          
    var mail = actions.create("mail");
      mail.parameters.to = "emailID";      
      var document_name= node.properties["cm:name"];
      mail.parameters.subject = loggedinuser+" has recommended "+document_name;
      var text= loggedinuser+" has recommended "+document_name+" document to you";
      text += "\n"+"Comment provided:::"+comment;
      mail.parameters.text = text;
      logger.log("Body is "+mail.parameters.text);
      mail.execute(companyhome);

But now I have to send it with Email Template like notify-email.ftl (of share which is the template for invite user on site). I checked that code but unable to understand and in that code invite user name is not passed to the template but I want to pass document name to the template, Please guide me how to do that ?

Also how to call java class from share (presentation webscript) —> datawebscript(Which calls javaclass for email sending) —> javaclass (which I have to call for email sending with custom email template) ?

Please guide me.  Any help in this matter by any body is highly appreciated.

Thanks!
-Nirvan

pawel_rzeszowsk
Champ in-the-making
Champ in-the-making
Hello nirvanvjain,
But now I have to send it with Email Template like notify-email.ftl (of share which is the template for invite user on site). I checked that code but unable to understand and in that code invite user name is not passed to the template but I want to pass document name to the template, Please guide me how to do that ?
You can pass the email template as the parameter in your custom email action.

Also how to call java class from share (presentation webscript) —> datawebscript(Which calls javaclass for email sending) —> javaclass (which I have to call for email sending with custom email template) ?

You can call the datawebscript from theShare client. In the datawebscript you will call the custom java action. You can pass a nodeRef to the email template in url (if it will be GET webscript, and the email nodeRef is already in the Alfresco Repository). You can also pass the template in the POST webscript.

Best Regards,
Pawel Rzeszowski.