This documentation is archived and is not being maintained.

IAlertNotifyHandler.OnNotification Method

Windows SharePoint Services 3

Occurs after an alert is sent and returns information about the alert notification.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

bool OnNotification(
	SPAlertHandlerParams ahp


Type: Microsoft.SharePoint.SPAlertHandlerParams
An SPAlertHandlerParams structure that contains information about the alert.

Return Value

Type: System.Boolean
true if Windows SharePoint Services marks the notification as processed; otherwise false.

Create a class that inherits from the IAlertNotificationHandler interface and uses the OnNotification method. This allows you to intercept the outgoing alert emails and modify them. We can access most of the properties for the alert and with some xml parsing and SharePoint object model code, we can extract all the information we need to build up the email. Use this information to construct the HTML stub to display the email based on your requirements and send the email out using SharePoint’s SendMail functionality.

The example formats the output to resemble the default alert template email as closely as possible, you can customize it further to suit your needs.


Include the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces in the project.

    public class Class1:IAlertNotifyHandler
        #region IAlertNotifyHandler Members
        public bool OnNotification(SPAlertHandlerParams ahp)
                SPSite site = new SPSite(ahp.siteUrl+ahp.webUrl);
                SPWeb 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)
                 else if(ahp.eventData[0].eventType==2)
                 else if(ahp.eventData[0].eventType==3)

         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;