发送Alfresco网站日历活动的电子邮件通知

时间:2014-01-22 07:40:05

标签: spring lucene cron alfresco alfresco-share

我正在尝试为日历活动实施通知。我跟着

中的讨论

Email Notifications on Calendar Events in Alfresco

到了这封信,但还是无法让它发挥作用。我想在日历活动开始前2天根据日历活动发送通知。它应该只发送给网站成员(值得注意的是,网站成员和所有用户一般都是从ldap服务器中挑选出来的)。

我的scheduled-action-services-context.xml如下所示:

        <!--
Define the model factory used to generate object models suitable for use with freemarker templates.
-->
<bean id="templateActionModelFactory" class="org.alfresco.repo.action.scheduled.FreeMarkerWithLuceneExtensionsModelFactory">
    <property name="serviceRegistry">
        <ref bean="ServiceRegistry"/>
    </property>
</bean>

        <!--
Execute the script /Company Home/Record Management/testscript.js
-->
<bean id="runScriptAction" class="org.alfresco.repo.action.scheduled.SimpleTemplateActionDefinition">
    <property name="actionName">
        <value>script</value>
    </property>
    <property name="parameterTemplates">
        <map>
            <entry>
                <key>
                    <value>script-ref</value>
                </key>
                <!-- Note that as of Alfresco 4.0, due to a  Spring upgrade, the FreeMarker ${foo} entries must be escaped -->
                <value>\$\{selectSingleNode('workspace://SpacesStore', 'lucene', 'PATH:"/app:company_home/app:dictionary/app:scripts/cm:calendar_notify.js"' )\}</value>
            </entry>
        </map>
    </property>
    <property name="templateActionModelFactory">
        <ref bean="templateActionModelFactory"/>
    </property>
    <property name="dictionaryService">
        <ref bean="DictionaryService"/>
    </property>
    <property name="actionService">
        <ref bean="ActionService"/>
    </property>
    <property name="templateService">
        <ref bean="TemplateService"/>
    </property>
</bean>

 <!--
  Run the script every minute - select the single node company home that is not used ...
-->
<bean id="runScript" class="org.alfresco.repo.action.scheduled.CronScheduledQueryBasedTemplateActionDefinition">
    <property name="transactionMode">
        <value>UNTIL_FIRST_FAILURE</value>
    </property>
    <property name="compensatingActionMode">
        <value>IGNORE</value>
    </property>
    <property name="searchService">
        <ref bean="SearchService"/>
    </property>
    <property name="templateService">
        <ref bean="TemplateService"/>
    </property>
    <property name="queryLanguage">
        <value>lucene</value>
    </property>
    <property name="stores">
        <list>
            <value>workspace://SpacesStore</value>
        </list>
    </property>
    <property name="queryTemplate">
        <!--<value>+@ia\:fromDate:\$\{luceneDateRange(now, \"P10D\")\} AND +PATH:"/app:company_home/st:sites/cm:prova/cm:calendar//*"</value>-->
                      <value>+PATH:"/app:company_home/st:sites//*/cm:calendar//*" AND   +@ia\:fromDate:[NOW TO MAX]</value>

    </property>
    <property name="cronExpression">
        <value>0 0/10 * * * ?</value>
    </property>
    <property name="jobName">
        <value>jobD</value>
    </property>
    <property name="jobGroup">
        <value>jobGroup</value>
    </property>
    <property name="triggerName">
        <value>triggerD</value>
    </property>
    <property name="triggerGroup">
      <value>triggerGroup</value>
    </property>
    <property name="scheduler">
        <ref bean="schedulerFactory"/>
    </property>
    <property name="actionService">
        <ref bean="ActionService"/>
    </property>
    <property name="templateActionModelFactory">
        <ref bean="templateActionModelFactory"/>
    </property>
    <property name="templateActionDefinition">
        <ref bean="runScriptAction"/> <!-- This is name of the action (bean) that gets run -->
    </property>
    <property name="transactionService">
        <ref bean="TransactionService"/>
    </property>
    <property name="runAsUser">
        <value>System</value>
    </property>
</bean>

我的电子邮件模板位于

位置

公司主页&gt;数据字典&gt;电子邮件模板&gt;通知电子邮件模板

,模板如下:

 <html>
 <head>
  <style type="text/css"><!--
  body
  {
     font-family: Arial, sans-serif;
     font-size: 14px;
     color: #4c4c4c;
  }

  a, a:visited
  {
     color: #0072cf;
  }

  .activity a
  {
     text-decoration: none;
  }

  .activity a:hover
  {
     text-decoration: underline;
  }
  --></style>
</head>

 <body bgcolor="#dddddd">
<#assign displayPaths=document.displayPath?split("/")>
<#assign site=displayPaths[3]>
<#assign contenuto=document.content>
  <table width="100%" cellpadding="20" cellspacing="0" border="0" bgcolor="#dddddd">
     <tr>
        <td width="100%" align="center">
           <table width="70%" cellpadding="0" cellspacing="0" bgcolor="white" style="background-color: white; border: 1px solid #aaaaaa;">
              <tr>
                 <td width="100%">
                    <table width="100%" cellpadding="0" cellspacing="0" border="0">
                       <tr>
                          <td style="padding: 20px 30px 0px;">
                             <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                   <td>
                                      <div style="font-size: 22px; padding-bottom: 4px;">
                                         Clinical Information Network reminds you that tomorrow ...
                                      </div>
                                      <div style="font-size: 14px; margin: 18px 0px 24px 0px; padding-top: 18px; border-top: 1px solid #aaaaaa;">


                                            <div class="activity">
                                               title: ${document.properties["{http://www.alfresco.org/model/calendar}whatEvent"]}
 <br></br>
 <br></br>
 description: ${document.properties["{http://www.alfresco.org/model/calendar}descriptionEvent"]}
  <br></br>
  <br></br>
  date: ${document.properties["{http://www.alfresco.org/model/calendar}fromDate"]?date}
  <br></br>
  <br></br>
  from: ${document.properties["{http://www.alfresco.org/model/calendar}fromDate"]?time}
  <br></br>
  <br></br>
  where: ${document.properties["{http://www.alfresco.org/model/calendar}whereEvent"]}

                                            </div>
                                            <div style="font-size: 11px; padding: 4px 0px 12px 0px;">
                                            </div>
                                      </div>
                                   </td>
                                </tr>
                             </table>
                          </td>
                       </tr>
                       <tr>
                          <td>
                             <div style="border-top: 1px solid #aaaaaa;">&nbsp;</div>
                          </td>
                       </tr>
                       <tr>
                         <td style="padding: 0px 30px; font-size: 13px;">
                             Please do not reply to this mail, the complete calendar is at:
                http://host:8080/share/page/site/${site}/calendar
                          </td>
                       </tr>
                       <tr>
                          <td>
                             <div style="border-bottom: 1px solid #aaaaaa;">&nbsp;</div>
                          </td>
                       </tr>
                       <tr>
                          <td style="padding: 10px 30px;">
                             <img src="${shareUrl}/themes/default/images/logo.png" alt="" width="117" height="48" border="0" />
                          </td>
                       </tr>
                    </table>
                 </td>
              </tr>
           </table>
        </td>
     </tr>
  </table>
 </body>
 </html>

中找到的calendar_notify.js javascript
Company_Home > Data Dictionary > Scripts

如下所示:

var titoloEvento = document.properties["{http://www.alfresco.org/model/calendar}whatEvent"];
var fromDate = document.properties["{http://www.alfresco.org/model/calendar}fromDate"];

var today = new Date();

fromDate.setHours(0,0,0);
today.setHours(0,0,0);

var milli_fromDate = fromDate.getTime();
var milli_today = today.getTime();

var diff = fromDate - today;

var num_days =Math.round(diff/(86400000));

var person;
var email;

if (num_days == 1) {

  var displayPaths=document.displayPath.split("/");
  var siteName = displayPaths[3];
  var site=siteService.getSite(siteName);

 var siteMembers = site.listMembers(null,null,0);

 if(siteMembers !=null){
        for (userName in siteMembers ){

               person = people.getPerson(userName);

               email = person.properties["cm:email"];

             var mail = actions.create("mail");

             mail.parameters.html = "html";

             mail.parameters.to = email;

             mail.parameters.template =   search.findNode("workspace://SpacesStore/f98619dc-7b09-40c6-8057-2867728c45a0"); //please set the correct node reference for the email template

             mail.parameters.subject = "Share reminder: "+titoloEvento;
             mail.parameters.from = "clinicalinformationnetwork@gmail.com";

             // execute action against a document   
             mail.execute(document);
     }
  }
}

可能导致它失败的原因是什么?我试图在过去48小时内搞清楚,但我仍然不明白为什么它没有执行。

1 个答案:

答案 0 :(得分:1)

虽然这个答案可能为时已晚,但在这里给出一些答案仍然很好。因为我最近碰巧尝试设置这个功能。

经过一段时间的挖掘,我终于可以在我的Alfresco中工作了。以下是您可能想要检查的一些事项:

  1. 检查alfresco根文件夹中的alfresco.log。每次运行计划任务时,您可能会看到一些例外情况,它可能会为您提供线索。

  2. 需要仔细检查"mail.parameters.template = search.findNode...."中的参考ID,指向电子邮件模板的正确节点。

  3. 您可能没有正确设置SMTP邮件服务器。谷歌SMTP露天找到它。

  4. 对于大多数SMTP服务器,他们会检查“来自”字段以匹配您的登录帐户。确保"mail.parameters.from ="正确无误。

  5. Gmail SMTP不起作用。看起来Gmail需要Alfresco不遵守的更强大的安全客户端。

  6. 为了进行调试,一种简单的方法是将以下语句添加到javascript的某些点。警告信息也将放在alfresco.log中。 logger.warn("....");

  7. 希望这有帮助。