Search code examples
emailnotificationsumbraco

Umbraco - when editor create content send email notification to admin


Is it possible? I am an admin. I want to be notified by email when editor (or writer or whom ever with the access) creates some content (e.g. enters some News in News document type). And how? I use Umbraco 7.5


Solution

  • You need to code into Umbraco ContentService events.

    The following should get you started. It will be triggered whenever an item is published.

    Be careful what you wish for though. You may get a barrage of useless emails if somebody publishes a parent node along with all of its child nodes.

    There are other events that you can hook into so please refer to documentation at 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
                }
            }
        }
    }