I wrote a custom handler to rewrite the urls in the alert messages: that's because separate frontends exists for FBA users and internal (active directory) users. default mail messages ships with links to the default site, the one with integrated authentication, but when the recipient is an external user these links should be changed to refer to the external frontend.
the custom notification handler is executed correctly for immediate notification alerts but never fires for digest.
I made a copy of the alerttemplates.xml file and added to the properties of the template SPAlertTemplateType.DocumentLibrary
, SPAlertTemplateType.GenericList
and SPAlertTemplateType.WebPageLibrary
:
<NotificationHandlerAssembly>MySharepointHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcdabcdabcd</NotificationHandlerAssembly>
<NotificationHandlerClassName>MySharepointHandler.MyNotifyHandler</NotificationHandlerClassName>
here is the code of the handler stripped to the core, error handling removed:
public class MyNotifyHandler : IAlertNotifyHandler
{
public bool OnNotification(SPAlertHandlerParams ahp)
{
using (new SPMonitoredScope("MySharepointHandler.MyNotifyHandler OnNotification"))
{
using (SPSite site = new SPSite(ahp.siteUrl + ahp.webUrl))
{
using (SPWeb web = site.OpenWeb())
{
string to = ahp.headers["to"];
if (to.IndexOf("@mydomain.com") < 0)
{
string NewBody = ahp.body;
NewBody = NewBody.Replace(InternalURL, ExternalURL);
SPUtility.SendEmail(web, ahp.headers, NewBody);
}
else
{
SPUtility.SendEmail(web, ahp.headers, ahp.body);
}
return true;
}
}
}
}
}
the handler is executed successfully for immediate alerts and the messages are altered by the handler: when digest alerts are sent the handler is completely ignored, it does not fire.
am I missing anything obvious? is there any error in the code or xml fragment?