cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript to send Email notifications

anwar501pasha
Champ in-the-making
Champ in-the-making
Hi All,

I Have a business requirement where I need to send Email Notification along witht he Email templates.

I have a JavaScript code using which i was able to send the mails from the Workflow using the code below.

                                                                              var mail = actions.create("mail");
                mail.parameters.to = emailAddress;
                mail.parameters.subject = "Please review this task" + bpm_workflowDescription;
                mail.parameters.from = initiator.properties.email;
                var mailSubject = mail.parameters.subject;
                logger.log("mailSubject: " + mailSubject);
                mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/notify_user_email.ftl");
                var mailMatter = mail.parameters.text;
                mail.parameters.text = "sdffdsfsdf";
                mail.execute(bpm_package);

How can I use the same code in webscripts to send email.

please help me

Thanks & Regards,
Anwar
7 REPLIES 7

mrogers
Star Contributor
Star Contributor
You can run exactly the same code in a java script web script.

malliswar
Champ in-the-making
Champ in-the-making
hi mrogers,

            like you mentioned in your comment i tried putting the code in webscript
like below

<code>
<html>

<div class="dashlet">
<div class="title"><font color=#0795D0><b>test</b></font></div>
<div class="body">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
function email()
{
var parent = space.getParent();
var siteShortName = space.getSiteShortName();
var siteGroup = "GROUP_site_" + siteShortName;

var template = "Data Dictionary/Email Templates/Notify Email Templates/test.html.ftl";

// create mail action
var mail = actions.create("mail");
mail.parameters.to_many = siteGroup;

mail.parameters.subject="New Discussion Started in " + siteShortName;
//mail.parameters.text="blablabla";
mail.parameters.template = companyhome.childByNamePath(template);

//execute action against a document
mail.execute(document);
}
email();
</script>


</div>
</div>

</html>
<code>

but i get tis error in my log file

org.springframework.extensions.webscripts.WebScriptException: 03070017 Failed to execute script 'classpath*:alfresco/site-webscripts/org/alfresco/components/dashlets/test.get.js': 03070016 ReferenceError: "actions" is not defined. (file:/home/malliswarreddyb/alfresco-5.0.a/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets/test.get.js#3)

please help me with this

Thanks in advance

anwar501pasha
Champ in-the-making
Champ in-the-making
HI mrogers,

Thanks fo the quick reply.

I have tried the above mentioned code to send Email notifications,  but I have the problem with the mail.execute() method. The mail.execute() method requires an input parameter called 'bpm_package' or 'NodeRef' object how can I get these objects into my webscripts.

Thanks & Regards,
Anwar

anwar501pasha
Champ in-the-making
Champ in-the-making
I have solved this.

Thanks

Anwar

jenn_l
Champ on-the-rise
Champ on-the-rise
Hi Anwar ,

I have same situation here, where I want a Javascript to send an email to the current user when this user has paste a document in a space.
How did you manage the javascript to execute the mail?
Can you share this with us?

Thanks,
Jenny

icart
Champ in-the-making
Champ in-the-making
Check out the example adhoc workflow in …\apache-tomcat-6.0.20\webapps\alfresco\WEB-INF\classes\alfresco\workflow\adhoc_processdefinition.xml
It has the following code:

      <transition name="" to="completed">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
              if (wf_notifyMe)
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.text = "It's done";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>

sgartner
Champ on-the-rise
Champ on-the-rise
I have tried the above mentioned code to send Email notifications,  but I have the problem with the mail.execute() method. The mail.execute() method requires an input parameter called 'bpm_package' or 'NodeRef' object how can I get these objects into my webscripts.

This is an old thread, but didn't give a satisfactory answer for me.  Since I figured out a simple solution I thought I would post it.  Assuming that you have a "person" that you are sending e-mail to (or a logged-in user) you have a NodeRef (the person) quite handy.  For example:


var mail = actions.create("mail");
mail.parameters.to = thePerson.properties["cm:email"];
mail.parameters.subject = "Your user name";
mail.parameters.from = "admin@mysite.com";
mail.parameters.text = "Your user name is: '" + thePerson.properties['cm:userName'] + "'.";
mail.execute(thePerson);