Implementing Alert Handlers
Published: May 2010
Alert handlers are triggered only when the user has subscribed to e-mail alerts. They are not triggered when the user has chosen SMS alerts.
You can use the following procedure to implement an alert handler.
To implement an alert handler
Register the assemblies in the global assembly cache.
Connect the alert template to the handler by using the Properties element of the alert template in the following format:
<Properties> <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>
Alert templates are stored in AlertTemplates.xml and AlertTemplates_SMS.xml. These templates define the format, contents, and properties used to create alert messages from each list type. Developers can customize alerts by modifying a copy of one or both of these files and then loading the customized alert templates by using the command stsadm -o updatealerttemplates.
Do not modify AlertTemplates.xml or AlertTemplates_SMS.xml. These files may be overwritten when a service pack is installed. To make changes, make a copy of one or both files, edit the copy, and then make one or two calls of the stsadm -o updatealerttemplates command to override the original templates with your changes. Your changes are stored in the SharePoint Foundation configuration database. For details, see Alerts Overview and AlertTemplates Schema.
If you make a change to a given SPAlertTemplateType.* template outside of the Format element, you must make the same change to the corresponding SPSmsAlertTemplateType.* template.
To catch the event when an alert is triggered, implement IAlertNotifyHandler. IAlertNotifyHandler.OnNotification is called when the alert is triggered. A SPAlertHandlerParams object is passed to the function. Then send the message with either an e-mail sending method such as SendEmail or an SMS message sending method, such as SendMessage(String).
To catch the event when a new alert is created or updated (so that you can change its properties or set new properties), implement the IAlertNotifyHandler interface. PreUpdate is called before the changes to the alert are committed to the database; PostUpdate is called after the changes are committed.