Customizing Email Alerts


Alerts are a way that users keep informed about changes to document libraries, lists, search results, and virtually all SharePoint content without having to check each site manually on a periodic basis. Through email, SharePoint alerts the users to changes. Figure 5.6 shows a typical alert message. SharePoint generated this message when a user deleted a file from a document library. Alert messages can be customized through NOTIFSITEHDR.XML, NOTIFLISTHDR.XML, NOTIFITEM. XML, and NOTIFSITEFTR.XML, which can be found in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\XML folder.

Figure 5.6. Default styled alert email.


The summation of these four XML files defines the HTML email message sent for the alert. Listing 5.3 details the HTML email of Figure 5.6. As shown in the bolded comments of Listing 5.3, Share-Point renders the NOTIFSITEHDR.XML first and then appends it with NOTIFLISTHDR.XML, NOTIFITEM.XML, and finally NOTIFSITEFTR.XML.

Listing 5.3. HTML Source of Figure 5.6

<!--[ Begin Source: "NotifSiteHdr.xml" ]-->  <HTML dir=ltr>  <HEAD>   <TITLE></TITLE>   <STYLE type="text/css"><!--    .ms-notif-descriptiontext {      color: black;      font-family: verdana;      font-size: 8pt;     }    .ms-notif-subsmanageheader {      background-color: #F2F2F2;      font-family: verdana;      font-size: 8pt;      text-align: left;      text-decoration: none;      font-weight: bold;      vertical-align: top;     }    .ms-notif-titlearea {      font-family: verdana;      font-size: 9pt;     }    .ms-notif-pagetitle {      color: black;      font-family: arial;      font-size: 14pt;      font-weight: normal;     }    .ms-notif-sectionline {      background-color: #2254b1;     }   --></STYLE>  </HEAD>  <BODY marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"        text="#000000"    link="#1B55FB" vlink="#BB1CFF" alink="#FF1C2C">   <TABLE height="100%" width="100%" cellpadding="0" cellspacing="0"          border="0">    <TR>     <TD valign="top">     <TABLE width="100%">      <TR><TD  colspan="2" height="1">        Alert result      </TD></TR>      <TR><TD  colspan="2" height="1">       <A href="http://localhost:81/MyFirstSiteDefinition">        http://localhost:81/MyFirstSiteDefinition - My First Site        Definition       </A>      </TD></TR>  <!--[ Begin Source: "NotifListHdr.xml" ]-->       <TR><TD>&nbsp;</TD></TR>       <TR><TD  colspan="2" height="1">        <A href=          "http://localhost:81/MyFirstSiteDefinition/Shared%20Documents">         Shared Documents        </A>        Summary</TD>       </TR>  <!--[ Begin Source: "NotifItem.xml" ]-->       <TR>       <TD >         My Text File.txt was deleted by (unknown) at 3/29/2005 3:20 PM.       </TD></TR>  <!--[ Begin Source: "NotifSiteFtr.xml" ]-->       <TR><TD>&nbsp;</TD></TR>       <TR><TD  colspan="2" height="1">        Go to        <A href= "http://localhost:81/MyFirstSiteDefinition/_layouts/1033/MySubs.aspx">          My Alerts         </A> to edit, delete, or view your alerts.        </TD></TR>       </TABLE>      </TD>     </TR>    </TABLE>   </BODY>  </HTML> 

In general, NOTIFSITEHDR.XML defines high-level information about the email. It defines the email subject, HTML styles, opening HTML body tag, and information on the site where the alert originated. NOTIFLISTHDR.XML provides information on the list where the alert originated. NOTIFITEM.XML provides information on the specific list or library item that generated the alert. Finally, NOTIFSITEFTR.XML provides a link to the site's administrative page that manages alerts and closes the HTML tags opened in NOTIFSITEHDR.XML. In actuality, you could have consolidated the code of all four files into one file.

Listing 5.4 details a portion of our modified NOTIFSITEHDR.XML file. The CAML code shown in this file is representative of the code in the other XML files. Microsoft first tends to define variables, through SetVar, that will be used in later sections and then generates the email's HTML message. As stated before, this is simply what Microsoft did. You are not required to follow this pattern. However, from a best practice standpoint, it is preferred if you follow their lead.

Listing 5.4. Partial Listing of NOTIFSITEHDR.XML

<xml>   <SetVar Name="NotifyTitle" Scope="Request">     <Switch>       <Expr>         <GetVar Name="AlertFrequency"/>       </Expr>       <Case Value="0">         <HTML>Alert result</HTML>       </Case>       <Case Value="1">         <HTML>Daily Summary</HTML>       </Case>       <Case Value="2">         <HTML>Weekly Summary</HTML>       </Case>     </Switch>   </SetVar> <SetVar Name="Subject" Scope="Request">   <HTML><![CDATA[SharePoint Alert: ]]></HTML>     <IfEqual>       <Expr1>         <GetVar Name="AlertFrequency"/>       </Expr1>       <Expr2>         <HTML>0</HTML>       </Expr2>       <Then>         <Switch>           <Expr>             <GetVar Name="EventType"/>           </Expr>           <Default>             <GetVar Name="ItemName"/>             <HTML> has been changed by </HTML>             <GetVar Name="ModifiedBy"/>           </Default>           <Case Value="1">             <GetVar Name="ItemName"/>             <HTML> has been added by </HTML>             <GetVar Name="ModifiedBy"/>           </Case>           <Case Value="2">             <GetVar Name="ItemName"/>             <HTML> has been modified by </HTML>             <GetVar Name="ModifiedBy"/>           </Case> . . .         </Switch>       </Then>       <Else>         <GetVar Name="SiteName"/>         <HTML><![CDATA[ ]]></HTML>         <GetVar Name="NotifyTitle"/>       </Else>     </IfEqual>   </SetVar>   <HTML>     <![CDATA[       <!--[ Begin Source: "NotifSiteHdr.xml" ]-->       <HTML dir=ltr>         <HEAD>           <TITLE></TITLE>           <STYLE type="text/css"><!--             .ms-notif-descriptiontext {                color: black;                font-family:     ]]>   </HTML> . . . 

In Listing 5.4, two variables are instantiated through SetVarNotifyTitle and Subject. The resulting NotifyTitle value is reused (which is always preferable to recalculating) several times throughout NOTIFSITEHDR.XML with the aid of GetVar. The Subject variable is a special variable that SharePoint will read to specify the email's subject. It is not referenced with GetVar in any of the XML files.

The only modification we have made to NOTIFSITEHDR.XML in Listing 5.4 was to insert the "SharePoint Alert:" into the Subject variable's definition. Thus the new subject will now be prefixed with "Share-Point Alert:" for all subsequent alerts. An email with the updated subject is shown in Figure 5.7.

Figure 5.7. Alert email with modified subject.


The remainder of the file generates its portion of the HTML email. It should be noted that you can access several predefined variables through GetVar. These variables are summarized in Table 5.1.

Table 5.1. Predefined Variables Accessible within the Alert XML Files

Variable Name

Description

AlertFrequency

Specifies how frequently the user chose to be alerted. Valid integer values include: 0 (immediate), 1 (daily), and 2 (weekly).

EventType

Specifies the event type that triggered this alert. Valid integer values include: 1 (item added), 2 (item modified), 4 (item deleted), 16 (discussion added), 32 (discussion modified), 64 (discussion deleted), 128 (discussion closed), and 256 (discussion activated).

ItemName

Specifies the item's name.

ItemUrl

Specifies the item's absolute URL.

ListName

Specifies the list's title.

ListUrl

Specifies the list's absolute URL.

ModifiedBy

Specifies the person who last modified the item.

MySubsUrl

Specifies the site's alerts administration page.

SiteLanguage

Specifies the site's LCID.

SiteName

Specifies the site's title.

SiteUrl

Specifies the site's absolute URL.

TimeLastModified

Specifies the item's modification time.


Keep in mind that the SharePoint Timer Service will need to be recycled before any changes to the notification XML files are reflected in alert emails. Executing IISReset has no affect on the alert subsystem. Remember, it is the SharePoint Timer Service that sends the alert emails.




SharePoint 2003 Advanced Concepts. Site Definitions, Custom Templates, and Global Customizations
SharePoint 2003 Advanced Concepts: Site Definitions, Custom Templates, and Global Customizations
ISBN: 0321336615
EAN: 2147483647
Year: 2006
Pages: 64

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net