文章編號: 948321 - 上次校閱: 2008年10月20日 - 版次: 2.0

如何在 Microsoft Office SharePoint 伺服器中建立自訂的電子郵件警示處理常式

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
全部展開 | 全部摺疊

結論

本文將告訴您,如何在 Microsoft Office SharePoint Server 2007 中建立自訂的電子郵件警示處理常式。本文所述的方法會使用 IAlertNotificationHandler 介面攔截電子郵件警示,並加以修改。

若要在 Microsoft Office SharePoint Server 2007 任何下列案例中建立自訂的電子郵件警示處理常式:
  • 欄位,如 ItemName] 欄位會被截斷的電子郵件警示 70 個字元。如果要解決 70 個字元的限制,使用 [其他相關資訊 > 一節中的 [所述方法]。
  • 您想要在電子郵件警示中嵌入額外的內容。
  • 您想要變更版面配置] 或 [電子郵件警示的外觀。

其他相關資訊

這個方法會建立的類別的繼承自 IAlertNotificationHandler 介面,然後,使用 OnNotification 方法。這個方法可讓您攔截外寄的電子郵件警示,並修改它們。您可以存取大部分的警示屬性。藉由使用 XML 剖析和 SharePoint 物件模型程式碼,您可以擷取您必須要有修改電子郵件警示的所有資訊。然後,您可以建置 HTML Stub 顯示根據您的需求的電子郵件提醒。而且,您也可以使用 SharePoint ’s SendMail 功能來傳送電子郵件提醒。

這些步驟包括格式化成密切類似預設通知範本電子郵件訊息輸出的範例程式碼。您可以修改這個範例程式碼中 HTML,以自訂產生的電子郵件警示。
  1. 建立繼承自 IAlertNotificationHandler 介面的類別專案。在專案中包含 Microsoft.SharePoint 命名空間和 Microsoft.SharePoint.Utilities 命名空間。

    Use the following code:
    //===================code start=====================
    public class Class1:IAlertNotifyHandler
    {
    
    #region IAlertNotifyHandler Members
    
    public bool OnNotification(SPAlertHandlerParams ahp)
    {
    SPSite site = null;
    SPWeb web = null;
    
    try
    {
    site = new SPSite(ahp.siteUrl+ahp.webUrl);
    web = site.OpenWeb();
    SPList list=web.Lists[ahp.a.ListID];
    SPListItem item = list.GetItemById(ahp.eventData[0].itemId) ;
    
    string FullPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl+"/"+list.Title+"/"+item.Name);
    string ListPath = HttpUtility.UrlPathEncode(ahp.siteUrl + "/" + ahp.webUrl + "/" + list.Title);
    string webPath=HttpUtility.UrlPathEncode(ahp.siteUrl+"/"+ahp.webUrl);
    
    string build = "";
    if (ahp.eventData[0].eventType==1)
    eventType="Added";
    else if(ahp.eventData[0].eventType==2)
    eventType="Changed";
    else if(ahp.eventData[0].eventType==3)
    eventType="Deleted";
    
    build = "<style type=\"text/css\">.style1 { font-size: small; border: 1px solid #000000;"+
    "background-color: #DEE7FE;}.style2 { border: 1px solid #000000;}</style></head>"+ 
    "<p><strong>"+ item.Name.ToString() +"</strong> has been "+eventType +"</p>"+
    "<table style=\"width: 100%\" class=\"style2\"><tr><td style=\"width: 25%\" class=\"style1\">"+
    "<a href="+ webPath +"/_layouts/mysubs.aspx>Modify my Settings</a></td>"+
    "<td style=\"width: 25%\" class=\"style1\"> <a href="+ FullPath +">View "+item.Name+"</a></td>"+
    "<td style=\"width: 25%\" class=\"style1\"><a href=" + ListPath + ">View " + list.Title + "</a></td>" +
    " </tr></table>";
    string subject=list.Title.ToString() ; 
    SPUtility.SendEmail(web,true , false, ahp.headers["to"].ToString(), subject,build);
    return false;
    }
    catch (System.Exception ex)
    {
    return false;
    }
    finally
    {
    if (web != null)
    web.Dispose();
    if (site != null)
    site.Dispose();
    }
    
    }
    
    #endregion
    }
    //===================code end=====================
    
  2. 將強帶正負號的.dll 檔加入至全域組件快取 (GAC)。您可以將組件拖曳到組件] 資料夾。或要註冊的.dll 檔使用 GACUtil 工具。

    如需詳細資訊請造訪下列 MSDN 網站]。如需詳細資訊,請按一下下列的文件編號,檢視 「 Microsoft 知識庫 」 中的文件:
    315682? (http://support.microsoft.com/kb/315682/ ) 如何將組件安裝在全域組件快取在 Visual Basic.NET 或 Visual Basic 2005 中
  3. 製作 alertTemplates.xml 檔案在下列資料夾中的複本:
    C:\Program Files\Common Files\Microsoft Shared\Web 伺服器 Extensions\12\Template\Xml
    CustomAlertTemplates.xml,這個新檔案名稱,然後儲存檔案。

    附註請勿直接修改 alertTemplates.xml 檔案。直接修改這個檔案不受支援。
  4. 編輯檔案,然後搜尋關鍵字屬性。 屬性區塊中加入下列行:
    <NotificationHandlerAssembly>AlertHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d59ecf2a3bd66904</NotificationHandlerAssembly>
              <NotificationHandlerClassName>AlertHandler.Class1</NotificationHandlerClassName>
        <NotificationHandlerProperties></NotificationHandlerProperties>
    虛設常式應該現在類似這樣:
            <Properties>
                <ImmediateNotificationExcludedFields>ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments;</ImmediateNotificationExcludedFields>
                <DigestNotificationExcludedFields>ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments;</DigestNotificationExcludedFields>
                <NotificationHandlerAssembly>AlertHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d59ecf2a3bd66904</NotificationHandlerAssembly>
                    <NotificationHandlerClassName>AlertHandler.Class1</NotificationHandlerClassName>
                    <NotificationHandlerProperties></NotificationHandlerProperties>
      </Properties>
    
    在警示的範本檔案中您想要的每個警示的範本] 區段中包含這個 XML 虛設常式。
  5. 在命令提示字元改 C:\Program Files\Common Files\Microsoft Shared\web 伺服器 extensions\12\BIN 目錄。然後,執行下列命令:
    stsadm-o updatealerttemplates-檔案名稱"C:\Program Files\Common Files\Microsoft Shared\Web 伺服器 Extensions\12\TEMPLATE\XML\customalerttemplates.xml"-url your_sharepoint_site url
  6. 執行下列命令:
    stsadm-o setproperty-pn 工作-立即-警示-pv 」 每隔 1 分鐘"
    這個命令指定頻率 SharePoint 伺服器會檢查立即傳送的警示。此值會指定以分鐘為單位。此測試頻率設定為 1 分鐘。

    如需詳細資訊請造訪下列 Microsoft 網站]:
    http://technet2.microsoft.com/windowsserver/WSS/en/library/0eb072fe-8321-483b-9d1e-3412e3f42a481033.mspx?mfr=true (http://technet2.microsoft.com/windowsserver/WSS/en/library/0eb072fe-8321-483b-9d1e-3412e3f42a481033.mspx?mfr=true)
  7. 請確定您有 SharePoint 針對外寄電子郵件設定。 如需有關如何設定外寄電子郵件訊息的詳細資訊,請造訪下列 Microsoft 網站]:
    http://technet2.microsoft.com/windowsserver/WSS/en/library/91570494-09ba-4537-904b-c61a6268d6bc1033.mspx?mfr=true (http://technet2.microsoft.com/windowsserver/WSS/en/library/91570494-09ba-4537-904b-c61a6268d6bc1033.mspx?mfr=true)
  8. 如果使用測試文件庫,請確定您有開啟的文件庫的提醒。
  9. 請執行下列命令:
    • iisreset
    • services.msc
  10. 在 [服務 MMC] 嵌入式管理單元,重新啟動 Windows SharePoint 服務計時器服務]。
完成這些步驟之後,自訂電子郵件警示處理常式應該加以設定。建立新的警示後,您應該會收到更新自訂電子郵件警示。

這篇文章中的資訊適用於:
  • Microsoft Office SharePoint Server 2007
  • Microsoft Office SharePoint Server 2007 for Search (Enterprise Edition)
  • Microsoft Office SharePoint Server 2007 for Search (Standard Edition)
關鍵字:?
kbmt kbhowto kbexpertiseadvanced kbinfo KB948321 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:948321? (http://support.microsoft.com/kb/948321/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。