【问题标题】:Sending email notifications for Alfresco site calendar events为 Alfresco 站点日历事件发送电子邮件通知
【发布时间】:2014-02-12 03:44:04
【问题描述】:

我正在尝试为日历事件实现通知。我已经关注了

中的讨论

Email Notifications on Calendar Events in Alfresco

信不信由你,但仍然无法正常工作。我想在日历事件前 2 天根据日历事件发送通知。它应该只将其发送给站点成员(值得注意的是,站点成员和所有用户通常都是从 ldap 服务器中挑选出来的)。

我的 schedule-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>

我的电子邮件模板在该位置找到

公司首页 > 数据词典 > 邮件模板 > 通知邮件模板

模板如下:

 <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 小时里,我一直试图弄清楚它,但我仍然不明白为什么它没有执行。

【问题讨论】:

  • 你的 -context 无效,你有一个重复的 bean id="runScript & 一个非封闭的 bean-tag
  • 很抱歉。由于逐段复制,我错误地粘贴了代码。我已经编辑了帖子以反映它的实际情况。对此感到抱歉。你能看看并告诉我可能是什么问题吗?

标签: spring lucene cron alfresco alfresco-share


【解决方案1】:

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

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

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

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

  3. 您可能没有正确设置 SMTP 邮件服务器。谷歌 SMTP alfresco 找出来。

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

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

  6. 为了调试,一个简单的方法是在 javascript 的某些点添加如下语句。警告消息也会放在 alfresco.log 中。 logger.warn("....");

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    相关资源
    最近更新 更多