Customizing the Message Text for Alerts

You can modify the content and format of e-mail alerts about changes made to list items in Microsoft Windows SharePoint Services by customizing XML files that are installed in the Local_Drive\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\1033\XML directory. These files include NotifItem.xml, NotifListHdr.xml, NotifSiteFtr.xml, and NotifSiteHdr.xml, each of them defining a specific part of the overall message that is sent. Each of these files implements a subset of Collaborative Application Markup Language (CAML) to construct the resulting HTML.

Warning  Changes that you make to files described in this topic may be overwritten when you install updates or service packs for Windows SharePoint Services, or when you upgrade an installation to the next product version.

The following table shows the parts of an e-mail alert for immediate notification of changes to a list item and which part each XML file constructs.

XML file Displayed content HTML content
NotifSiteHdr.xml Alert result http://Server_Name/sites/Site_Name - Site_Display_Name
<!--[ 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 class="ms-notif-titlearea" colspan="2" height="1">Alert result</TD></TR>
      <TR><TD class="ms-notif-titlearea" colspan="2" height="1">
       <A href="http://Server_Name/sites/Site_Name">http://Server_Name/sites/Site_Name - Site_Name</A>
      </TD></TR>
NotifListHdr.xml List_Display_Name Summary
 <!--[ Begin Source: "NotifListHdr.xml" ]-->
      <TR><TD>&nbsp;</TD></TR>
      <TR><TD class="ms-notif-subsmanageheader" colspan="2" height="1">
       <A href="http://Server_Name/sites/Site_Name/Doc_Lib">Doc_Lib</A> Summary
      </TD></TR>
NotifItem.xml File_Name was modified by User_Name at 10/12/2003 8:01 PM.
 <!--[ Begin Source: "NotifItem.xml" ]-->
      <TR>
       <TD class="ms-notif-descriptiontext">
        <A href="http://Server_Name/sites/Site_Name/Doc_Lib/File_Name">File_Name</A> was modified by User_Name at 10/12/2003 8:01 PM.
       </TD>
      </TR>
NotifSiteFtr.xml Go to My Alerts to edit, delete, or view your alerts.
 <!--[ Begin Source: "NotifSiteFtr.xml" ]-->
      <TR><TD>&nbsp;</TD></TR>
      <TR><TD class="ms-notif-descriptiontext" colspan="2" height="1">
       Go to <A href="http://Server_Name/sites/Site_Name/_layouts/1033/MySubs.aspx">My Alerts</A> to edit, delete, or view your alerts.
      </TD></TR>
     </TABLE>
    </TD>
   </TR>
  </TABLE>
 </BODY>
 </HTML>

To create a custom message for an alert, make customizations to the appropriate XML file as indicated in the previous table.

To construct the HTML for conveying the message, use the CAML GetVar element to return run-time values and the SetVar element to define variables. These elements can be used to return or set values in conjunction with the following CAML control statement elements, which are the only CAML elements supported in the XML files that define message contents:

The following table shows all the variables that are available for returning information about the item that triggered the alert. No other properties of the item are available at run time beyond those listed in the table. These variables can be assigned to the Name attribute of the GetVar element to return current values that can be used to customize a message.

Name Description
AlertFrequency The time interval for sending an alert. Possible values include 0 (immediate), 1 (daily), or 2 (weekly).
EventType The type of event. Possible 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 The title of the item.
ItemUrl The absolute URL for the item.
ListName The name of the list.
ListUrl The absolute URL for the list.
ModifiedBy The display name of the user who modified the item.
MySubsUrl The absolute URL for the My Alerts on this Site page in Site Settings.
SiteLanguage The locale identifier (LCID) for the language used on the site. For example, 1033 is the LCID for U.S. English.
SiteName The title of the site.
SiteUrl The absolute URL for the site.
TimeLastModified The time at which the item was last modified.

Example

This programming task shows how to use CAML to add custom text to alert messages based on whether an item is added, modified, or deleted. The example defines a different CSS style depending on the type of event.

The following code can be added to NotifSiteHdr.xml alongside other code blocks that use the SetVar element to define variables.

<SetVar Name="MyColor" Scope="Request">
  <IfEqual>
    <Expr1>
      <GetVar Name="AlertFrequency" />
    </Expr1>
    <Expr2>
      <HTML>0</HTML>
    </Expr2>
    <Then>
      <Switch>
        <Expr>
          <GetVar Name="EventType" />
        </Expr>
        <Default />
        <Case Value="0">
          <HTML>green</HTML>
        </Case>
        <Case Value="2">
          <HTML>blue</HTML>
        </Case>
        <Case Value="4">
          <HTML>red</HTML>
        </Case>
      </Switch>
    </Then>
    <Else />
  </IfEqual>
</SetVar>

The example uses the GetVar element to return the frequency of the alert. If the frequency is set to 0 (immediate), then a Switch element is executed that determines the color to use in the style definition. Depending on the type of event, each Case element specifies a different color.

Next, add a style definition to NotifSiteHdr.xml that uses the GetVar element to return the value of the MyColor variable and that specifies the font color and font size for the style.

<HTML><![CDATA[<!--[ Begin Source: "NotifSiteHdr.htm" ]-->
   <STYLE type="text/css"><!--

      .MyStyle {
         color: ]]></HTML>
         <GetVar Name="MyColor"/>
         <HTML><![CDATA[;
         font-family: verdana;
         font-size: 14pt;
         }

      .ms-notif-descriptiontext {
         color: black;
         font-family: ]]></HTML>
         .
         .
         .

Add the following code to NotifListHdr.xml, which determines the text to display when items are added, changed, or deleted.

<SetVar Name="MyText" Scope="Request">
  <Switch>
    <Expr>
      <GetVar Name="EventType" />
    </Expr>
    <Default />
    <Case Value="0">
      <HTML>
        <![CDATA[ Item Added! ]]>
      </HTML>
    </Case>
    <Case Value="2">
      <HTML>
        <![CDATA[ Item Changed! ]]>
      </HTML>
    </Case>
    <Case Value="4">
      <HTML>
        <![CDATA[ Item Deleted! ]]>
      </HTML>
    </Case>
  </Switch>
</SetVar>

Depending on the type of event, each Case element specifies different text.

To display the text in alert messages, add a row in NotifListHdr.xml that applies the MyStyle definition and that uses the GetVar element to return the value of the MyText variable.

<HTML>
  <![CDATA[  <!--[ Begin Source: "NotifListHdr.xml" ]-->
    <TR><TD>&nbsp;</TD></TR>
    <TR><TD class="MyStyle" colspan="2" height="1"> ]]>
</HTML>
<GetVar Name="MyText" HTMLEncode="TRUE" />
<HTML>
  <![CDATA[ </TD></TR>
      <TR><TD class="ms-notif-subsmanageheader" colspan="2" height="1"> ]]>
</HTML>

Restart the server for changes to take effect in your alert messages.

Users who subscribe to alerts for all changes that occur in a list will receive an e-mail message that includes a heading indicating the type of event that occurred when an item is added, modified, or deleted.