查看预定发布页面的请求和到期通知电子邮件

时间:2009-03-20 03:15:13

标签: sharepoint moss

我目前正在小型服务器场环境中运行发布门户。使用页面设置和计划表单发布页面我们已将内容配置为“向页面联系人发送内容审阅请求邮件”。我们已经针对电子邮件的频率尝试了许多不同的配置,但无论我们选择什么,都不会发送任何电子邮件。到期通知似乎也发生了同样的事情。

我们检查了服务器场的电子邮件设置,但它们似乎是正确的。警报和欢迎电子邮件都正常运行。有谁知道如何让这些工作?

1 个答案:

答案 0 :(得分:0)

在使用Reflector进行一些调查后,我们最终发现了电子邮件未被发送出去的原因(以及为什么不管我们在设置中更改了什么,它们都不会出现)

审核和到期通知通过事件处理程序,sharepoint计时器作业定义和名为Notification Pages / Notification List的自定义列表的组合来运行。事件的基本顺序如下:

  1. 在自动新内容页面的过程中,用户选择在特定时间点向他们发送评论或到期通知。随后签入并发布内容页面。
  2. 触发事件处理程序(ScheduledItemEventReceiver)并验证相关项目是否为ScheduledItem,并且它正在被批准。如果是这种情况,那么它将告诉该项目注册它的日程安排(ScheduledItem.Schedule(...))。
  3. 此过程负责为项目指定的计划开始日期和结束日期,确保它在正确的时间可用。此外,它应该将项目添加到通知列表(http://[Site名称] /通知页面/)。
  4. 计时器作业(NotificationJobDefinition)将定期查询通知列表中的项目,如果交付日期已过,它将向页面联系人发送审核或到期通知电子邮件。
  5. 所以这一切听起来不错,理论上应该完美,但是有一个问题。为了将项添加到通知列表,ScheduledItem.Schedule方法调用HandleScheduling方法。

    PublishingPage的HandleScheduling方法(继承自ScheduledItem)将调用UpdateNotificationList,而UpdateNotificationList又将一个项添加到通知列表中。 基础ScheduledItem类的HandleScheduling方法为空。

    看起来问题是,ScheduledItemEventReceiver类将它的对象实例化为ScheduledItem(基类),因此每当它调用HandleScheduling时,都不会发生任何事情。您可以浏览到通知列表(/ Notification Pages / AllItems.aspx - 需要网站集管理员权限),它完全为空。

    我们目前有一个解决方法。我们开发并部署了一个自定义事件接收器,它取代了ScheduledItemEventReceiver。它检查项目是否是发布页面,如果是,则使用一些反射来直接调用UpdateNotificationList方法。有了这个,我们开始看到项目按预期添加到通知列表中。

    public class ScheduledPageEventReceiver : SPItemEventReceiver
    {
        protected void HandleScheduling(PublishingPage page)
        {
            Type t = typeof(PublishingPage);
            MethodInfo notificationMethod = t.GetMethod("UpdateNotificationList",BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
            if (notificationMethod != null)
            {
                notificationMethod.Invoke(page, null);
            }
        }
    
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }
            if (properties.AfterProperties == null)
            {
                throw new ArgumentNullException("properties.AfterProperties");
            }
            object status = properties.AfterProperties["vti_doclibmodstat"];
            if ((status != null) && (Convert.ToInt32(status, CultureInfo.InvariantCulture) == 0)) //Approved
            {
                using (SPWeb web = properties.OpenWeb())
                {
                    SPListItem item = web.GetFile(properties.BeforeUrl).Item;
                    if (PublishingPage.IsPublishingPage(item) && PublishingPage.IsScheduledItem(item))
                    {
                        PublishingPage page = PublishingPage.GetPublishingPage(item);
                        HandleScheduling(page);
                        return; 
                    }
                }
            }
        }
    }