首页 > 解决方案 > Umbraco - 当编辑创建内容时向管理员发送电子邮件通知

问题描述

可能吗?我是管理员。我想在编辑(或作家或有权访问的人)创建一些内容(例如在新闻文档类型中输入一些新闻)时通过电子邮件收到通知。如何?我使用 Umbraco 7.5

标签: emailnotificationsumbraco

解决方案


您需要对 Umbraco ContentService 事件进行编码。

以下内容应该可以帮助您入门。每当发布项目时都会触发它。

不过要小心你的愿望。如果有人发布了父节点及其所有子节点,您可能会收到一连串无用的电子邮件。

您还可以加入其他事件,因此请参阅https://our.umbraco.com/Documentation/Reference/Events/ContentService-Events-v7上的文档。

using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;

namespace My.Namespace
{
    public class MyEventHandler : ApplicationEventHandler
    {

        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentService.Published += ContentServicePublished;
        }

        private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> args)
        {
            foreach (var node in args.PublishedEntities)
            {
                 // Your code to send email here
            }
        }
    }
}

推荐阅读