现在的位置: 首页 > 综合 > 正文

邮件通知定制

2013年05月24日 ⁄ 综合 ⁄ 共 4460字 ⁄ 字号 评论关闭

Moss自帶的發郵件通知(提酲我)功能往往達不到客戶想要的效果,下面我將介紹一下怎麼樣自定義這個通知(提酲我)的郵件內容。

1.      先了解通知(提酲我)的基本知識

a.       通知(提酲我)是由WSS的定時執行程式(Windows SharePoint Services Timer)來定時發郵件提醒的,在這之前請確保這個服務已經啟用,如果啟用了可以在工作管理員下的處理程序中看到有一個OWSTIMER.EXE的進程

b.      所發送通知(提酲我)的主旨與內容格式默認是在12"TEMPLATE"XML"alerttemplates.xml文件中定義的(註:此文件是不可以修改的)

c.       alerttemplates.xml中定義了各種類型的郵件模板,包括

ü   SPAlertTemplateType.GenericList:如沒有使用以下模板,則用此模板

ü   SPAlertTemplateType.DocumentLibrary:有关对文档库所做更改的通知

ü   SPAlertTemplateType.Survey:有关对调查所做更改的通知

ü   SPAlertTemplateType.Links:有关对链接所做更改的通知

ü   SPAlertTemplateType.Announcements:有关对声明所做更改的通知

ü   SPAlertTemplateType.Contacts:有关对联系人所做更改的通知

ü   SPAlertTemplateType.Events:有关对事件所做更改的通知

ü   SPAlertTemplateType.Tasks:有关对任务所做更改的通知

ü   SPAlertTemplateType.DiscussionBoard:有关对讨论板所做更改的通知

ü   SPAlertTemplateType.PictureLibrary:有关对图片库所做更改的通知

ü   SPAlertTemplateType.XMLForm:有关对 XML 表单所做更改的通知

ü   SPAlertTemplateType.DataConnectionLibrary:有关对数据连接库所做更改的通知

ü   SPAlertTemplateType.AssignedtoNotification:有关分配到任务列表和问题列表的通知

d.   通知的格式定義了郵件的內容,通知發送郵件的條件等,且其內容是由CAML組成
<AlertTemplate Type="List" Name="SPAlertTemplateType.GenericList">

 <Format>

    <Digest>

      <Subject>

      </Subject>

      <Header>

      </Header>

      <HeaderFieldsHeader>

      </HeaderFieldsHeader>

      <HeaderFields>

      </HeaderFields>

      <HeaderFieldsFooter>

      </HeaderFieldsFooter>

      <RowHeader>

      </RowHeader>

      <RowFields>

      </RowFields>

      <RowFooter>

      </RowFooter>

      <Footer>

      </Footer>

    </Digest>

    <Immediate>

      <Subject>

      </Subject>

      <Header>

      </Header>

      <Fields>

      </Fields>

      <Footer>

      </Footer>

    </Immediate>

 </Format>

 <Properties>

    <ImmediateNotificationExcludedFields>

    </ImmediateNotificationExcludedFields>

    <DigestNotificationExcludedFields>

    </DigestNotificationExcludedFields>

    <NotificationHandlerAssembly>

      Handler assembly strong name

    </NotificationHandlerAssembly>

    <NotificationHandlerClassName>

      Fully qualified class name

    </NotificationHandlerClassName>

    <NotificationHandlerProperties>

      Other option properties you want to pass

    </NotificationHandlerProperties>

    <UpdateHandlerAssembly>

      Assembly

    </UpdateHandlerAssembly>

    <UpdateHandlerClassName>

      Class name

    </UpdateHandlerClassName>

    <UpdateHandlerProperties>

      Other properties

    </UpdateHandlerProperties>

 </Properties>

 <Filters>

    <FilterDefinition>

      <FriendlyName></FriendlyName>

      <ShortName></ShortName>

      <Query>

        <Neq>

          <FieldRef name="EventDate/New"/>

          <FieldRef name="EventDate/Old"/>

        </Neq>

      </Query>

    </FilterDefinition>

 </Filters>

</AlertTemplate>

e.       如果要自定義某種類型的通知(如自定義文檔庫的通知),請先拷由一份alerttemplates.xml文件將其命名為其它的名稱(如CustomAlerttemplates.xml),再在CustomAlerttemplates.xml文件中修改其通知格式,修改完成後執行stsadm -o updatealerttemplates -filename "C:"Program Files"Common Files"Microsoft Shared"Web Server Extensions"12"TEMPLATE"XML"customalerttemplates.xml" -url your_sharepoint_site url與 stsadm -o setproperty -pn job-immediate-alerts -pv "every 1 minutes"
再IISRESET與重新啟用Windows SharePoint Services Timer服務即可

2.      使用DONET開發自義的通知

1.      創建一個類庫(如:CustomAlertTemplate)

2.      給這個類庫加上強命名空間

3.      引用Microsoft.SharePoint與Microsoft.SharePoint.Utilities;

4.      創建一個類(名稱如DocAlertTemplate)

5.      將這個類繼承自接口IAlertNotifyHandler

6.      實現IAlertNotifyHandler的OnNotification方法

7.      在OnNotification方法中調用SPUtility.SendEmail來發送郵件

8.      編輯這個類庫,將dll文件拖到GAC中去

9.      拷由一分alerttemplates.xml文件,重命名為CustomAlerttemplates.xml

10. 在CustomAlerttemplates.xml文件中找到SPAlertTemplateType.DocumentLibrary模板,在這個模板下的Properties節點中加入
<NotificationHandlerAssembly>CustomAlertTemplate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx</NotificationHandlerAssembly>   <NotificationHandlerClassName>CustomAlertTemplate.DocAlertTemplate</NotificationHandlerClassName>

<NotificationHandlerProperties></NotificationHandlerProperties>

11. 當然CustomAlerttemplates.xml文件中除了SPAlertTemplateType.DocumentLibrary模板以外的其它模板你也可以刪除也可以不刪除,而SPAlertTemplateType.DocumentLibrary模板的內容也可以為空,不過最後不要為空,如果為空的話,你在OnNotification方法中就取不到默認的內容了

12. 執行stsadm -o updatealerttemplates -filename "C:"Program Files"Common Files"Microsoft Shared"Web Server Extensions"12"TEMPLATE"XML"customalerttemplates.xml" -url your_sharepoint_site url 與 stsadm -o setproperty -pn job-immediate-alerts -pv "every 1 minutes"
再IISRESET與重新啟用Windows SharePoint Services Timer服務即可

3.      在開發過程中要註意的事項

a.       調試文件請附附加處理程序OWSTIMER.EXE而不是w3wp.exe

b.      如果不是第一次部署,而是部署後再更新了DLL文件,再將DLL文件拖到GAC目錄中去,那麼每次都要執行IISRESET與重起Windows SharePoint Services Timer服務才行

c.       如果是更新DLL文件再調試,這個時候應該跟蹤不到,必須讓服務執行一次後才能跟蹤到(如你定義的是A文件庫的通知,那麼更新後,必須先由A發送一次後,再執行a步驟即可以調試)

抱歉!评论已关闭.