+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Email alrts / notifications for any new content?

Email alrts / notifications for any new content?

4 posts, 0 answered
  1. Todd
    Todd avatar
    7 posts
    Registered:
    08 Apr 2014
    08 Apr 2014
    Link to this post

    We have SF project that is basically just a large document repository where different groups have their own folder that only they and their team have access to.  When people upload or change documents in their libraries all we would like a small group of owner/admins to receive an email notification.  In SharePoint they call this an alert?  Simple, but elusive.  Possible?

     Thanks!

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    11 Apr 2014
    Link to this post
    Hello Todd,

    One option is to use our EventHub implementation.
    EventHub is a centralized place in Sitefinity where you can subscribe for data events. You can find a list of the exposed content-specific events in the system here.
    However, in some specific scenarios, you might want to have a global event for all content, you can subscribe to the IDataEvent - it will be thrown on Create, Update, and Delete actions for all content. Inside the event handler you can get information about the:
    - Event action ("Created", "Updated", "Deleted")
    - item type
    - item ID
    - item ProviderName

    this data is sufficient to allow you to load the corresponding manager and retrieve the actual item.

    To wrap it up I've prepared a small sample:
    Copy Code
    Copy Code
    void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                if (e.CommandName == "Bootstrapped")
                {
                    EventHub.Subscribe<IDataEvent>(Content_Action);              
                }
            }
     
            private void Content_Action(IDataEvent @event)
            {
                var action = @event.Action;
                var contentType = @event.ItemType;
                var itemId = @event.ItemId;
                var providerName = @event.ProviderName;
                var manager = ManagerBase.GetMappedManager(contentType, providerName);
                var item = manager.GetItemOrDefault(contentType, itemId);
            }


    Another option is to add a decorator, which subscribes to the Publish method of Documents and sends an email to all subscribers of a mailing list. The implementation can be found bellow. It is for documents publishing and sends e-mails to subscribers from "Admins" mailing list, using "localhost" on port 26. Video of the sample.

    The Decorator class:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Lifecycle;
    using Telerik.Sitefinity.GenericContent.Model;
    using System.Net.Mail;
    using Telerik.Sitefinity.Libraries.Model;
    using Telerik.Sitefinity.Modules.Newsletters;
    using Telerik.Sitefinity.Security.Claims;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Model;
     
    namespace SitefinityWebApp.Decorators
    {
        public class CustomDocumentsDecorator : LifecycleDecorator
        {
            public CustomDocumentsDecorator(ILifecycleManager manager, LifecycleItemCopyDelegate copyDelegate, params Type[] itemTypes) : base(manager, copyDelegate, itemTypes)
            {
            }
     
            public CustomDocumentsDecorator(ILifecycleManager manager, Action<Content, Content> copyDelegate, params Type[] itemTypes)
                : base(manager, copyDelegate, itemTypes)
            {
            }
     
            protected override ILifecycleDataItemGeneric ExecuteOnPublish(ILifecycleDataItemGeneric masterItem, ILifecycleDataItemGeneric liveItem, System.Globalization.CultureInfo culture = null, DateTime? publicationDate = null)
            {
                if (masterItem is Document)
                {
                    var documentItem = masterItem as Document;
     
                    var manager = NewslettersManager.GetManager();
                    var mailingList = manager.GetMailingLists().Where(ml => ml.Title == "Admins").FirstOrDefault();
     
                    if (mailingList != null && mailingList.Subscribers().Count() > 0)
                    {
                        var mailMessage = new MailMessage();
                        mailMessage.From = new MailAddress("sender@server.com");
                        var subscribers = mailingList.Subscribers();
                        foreach (var subscriber in subscribers)
                        {
                            mailMessage.To.Add(new MailAddress(subscriber.Email));
                        }
                        mailMessage.Subject = String.Format("Document Item \"{0}\" Published", documentItem.Title.Value);
     
                        var user = GetCurrentUser();
                        string username = string.Empty;
     
                        if (user != null)
                        {
                            username = user.FirstName + " " + user.LastName;
                        }
     
                        mailMessage.Body = string.Format("A new document item has been published. Item with title {0} has been updated on {1} by {2}", documentItem.Title, DateTime.Now, username);
     
                        var client = new SmtpClient();
                        client.Host = "localhost";
                        client.Port = 26;
                        client.Send(mailMessage);
                    }
                }
                
                return base.ExecuteOnPublish(masterItem, liveItem, culture, publicationDate);
            }
     
            private SitefinityProfile GetCurrentUser()
            {
                var identity = ClaimsManager.GetCurrentIdentity();
     
                if (identity != null && identity.UserId != Guid.Empty)
                {
                    UserProfileManager profileManager = UserProfileManager.GetManager();
                    UserManager userManager = UserManager.GetManager("Default");
                    User user = userManager.GetUser(identity.UserId);
                    SitefinityProfile profile = null;
     
                    if (user != null)
                    {
                        profile = profileManager.GetUserProfile<SitefinityProfile>(user);
                        return profile;
                    }
                }
     
                return null;
            }
        }
    }

    The Global.asax additions:
    protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized_Decorator);
            }
     
            void Bootstrapper_Initialized_Decorator(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                ObjectFactory.Container.RegisterType<ILifecycleDecorator, Decorators.CustomDocumentsDecorator>(typeof(LibrariesManager).FullName,
                    new InjectionConstructor(
                        new InjectionParameter<ILifecycleManager>(null),
                        new InjectionParameter<Action<Content, Content>>(null),
                        new InjectionParameter<Type[]>(null))
                    );
            }
    I hope you find this helpful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Todd
    Todd avatar
    7 posts
    Registered:
    08 Apr 2014
    11 Apr 2014 in reply to Nikola Zagorchev
    Link to this post
    Thank you so much for this thoughtful and thorough answer.  I will be forwarding this to my Sitfinity managers to try and implement.  Will report back.  Thanks again!
  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    08 Dec 2016
    14 Apr 2014
    Link to this post
    Hi Todd,

    You can find more information about our EventHub and event driven development here. More information
    about our events system here.
    I hope you find this useful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered