0

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?

0

I found the explanation running this query with SSMS on the content database:

SELECT *
FROM SchedSubscriptions;

checking the relevant row I found that the value for AlertTemplateName is empty (not NULL but empty, '', zero length string).

The daily alert is created by a FBA management application: deleting the alert created by the FBA application and adding a new one using sharepoint builtin tools makes the alert customization work properly.

The difference in behaviour was because the immediate alerts were created using sharepoint builtin tools, that are properly filling the table for immediate alerts:

SELECT *
FROM ImmedSubscriptions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.