Email notifications to all subscribers when the new document is published

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I want to be able to send email notifications to list of subscribed users (<500 users) registered under membership provider as soon as a new document is published to content delivery.
This can be achieved in a number of ways in Sitecore.



What would be the best way to send this notification without affecting/slowing over all performance of application/publish pipeline/document library.



  1. Use workflow

  2. Subscribe to publish-related events

  3. Add code into the 'publish' pipeline









share|improve this question



























    up vote
    3
    down vote

    favorite












    I want to be able to send email notifications to list of subscribed users (<500 users) registered under membership provider as soon as a new document is published to content delivery.
    This can be achieved in a number of ways in Sitecore.



    What would be the best way to send this notification without affecting/slowing over all performance of application/publish pipeline/document library.



    1. Use workflow

    2. Subscribe to publish-related events

    3. Add code into the 'publish' pipeline









    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I want to be able to send email notifications to list of subscribed users (<500 users) registered under membership provider as soon as a new document is published to content delivery.
      This can be achieved in a number of ways in Sitecore.



      What would be the best way to send this notification without affecting/slowing over all performance of application/publish pipeline/document library.



      1. Use workflow

      2. Subscribe to publish-related events

      3. Add code into the 'publish' pipeline









      share|improve this question















      I want to be able to send email notifications to list of subscribed users (<500 users) registered under membership provider as soon as a new document is published to content delivery.
      This can be achieved in a number of ways in Sitecore.



      What would be the best way to send this notification without affecting/slowing over all performance of application/publish pipeline/document library.



      1. Use workflow

      2. Subscribe to publish-related events

      3. Add code into the 'publish' pipeline






      pipelines






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago









      Peter Prochazka

      3,8131734




      3,8131734










      asked 6 hours ago









      Umar D

      548




      548




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          I would use Workflow in your case.



          You need to create and assign different workflow for document templates on their standard values to make this working.



          There is an "Email action" OOTB that you can use in your workflow to send emails but you need to create custom class to send emails to your subscribed list.



          Just add this action after Auto Publish to your workflow like this and fill in the fields:



          enter image description here



          Insert text into Message field. Something like:




          We have new document for for! Check it out here: $itemUrl$




          Change Type field especially to your custom class definition:



          enter image description here



          Use Your_namespace_goes_here.SubscribersEmailAction, Your_assembly_name_goes_here notation in Type field. SubscribersEmailAction is name of class below.



          SubscribersEmailAction Class could be something similar to this code:



          using System.Net.Mail;
          using Sitecore.Data.Items;
          using Sitecore.Diagnostics;
          using Sitecore.Workflows.Simple;
          using Sitecore.Links;

          namespace Your_namespace_goes_here

          public class SubscribersEmailAction

          public void Process(WorkflowPipelineArgs args)

          Assert.ArgumentNotNull(args, "args");
          var processorItem = args.ProcessorItem;
          if (processorItem == null)
          return;

          var commandItem = processorItem.InnerItem;
          var fullPath = commandItem.Paths.FullPath;
          var from = GetText(commandItem, "from", args);
          var to = GetText(commandItem, "to", args);
          var mailServer = GetText(commandItem, "mail server", args);
          var subject = GetText(commandItem, "subject", args);
          var message = GetText(commandItem, "message", args);

          Error.Assert(to.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
          Error.Assert(from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
          Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);

          var smtpClient = string.IsNullOrWhiteSpace(mailServer)
          ? new SmtpClient()
          : new SmtpClient(mailServer);
          smtpClient.Send(new MailMessage(from, to)

          Subject = subject,
          Body = message
          );


          public string GetText(Item commandItem, string field, WorkflowPipelineArgs args)

          var text = commandItem[field];
          return text.Length > 0 ? ReplaceVariables(text, args) : string.Empty;


          private static string ReplaceVariables(string text, WorkflowPipelineArgs args)

          text = text.Replace("$itemUrl$", MediaUrl(args.DataItem));
          return text;


          private static string MediaUrl(Item item)

          if (item == null) return string.Empty;

          if (!item.Paths.IsMediaItem) return string.Empty;

          var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
          mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL);
          return mediaUrl;





          Code inspired by this blog post: https://jeffreyrondeau.wordpress.com/2015/02/25/extending-sitecore-workflow-email-action/



          You need to tweak a bit the code because you need to replace "To" field with email addresses from your subscribers list.






          share|improve this answer
















          • 1




            SPE can also be used!
            – Michael West
            1 hour ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "664"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14810%2femail-notifications-to-all-subscribers-when-the-new-document-is-published%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          I would use Workflow in your case.



          You need to create and assign different workflow for document templates on their standard values to make this working.



          There is an "Email action" OOTB that you can use in your workflow to send emails but you need to create custom class to send emails to your subscribed list.



          Just add this action after Auto Publish to your workflow like this and fill in the fields:



          enter image description here



          Insert text into Message field. Something like:




          We have new document for for! Check it out here: $itemUrl$




          Change Type field especially to your custom class definition:



          enter image description here



          Use Your_namespace_goes_here.SubscribersEmailAction, Your_assembly_name_goes_here notation in Type field. SubscribersEmailAction is name of class below.



          SubscribersEmailAction Class could be something similar to this code:



          using System.Net.Mail;
          using Sitecore.Data.Items;
          using Sitecore.Diagnostics;
          using Sitecore.Workflows.Simple;
          using Sitecore.Links;

          namespace Your_namespace_goes_here

          public class SubscribersEmailAction

          public void Process(WorkflowPipelineArgs args)

          Assert.ArgumentNotNull(args, "args");
          var processorItem = args.ProcessorItem;
          if (processorItem == null)
          return;

          var commandItem = processorItem.InnerItem;
          var fullPath = commandItem.Paths.FullPath;
          var from = GetText(commandItem, "from", args);
          var to = GetText(commandItem, "to", args);
          var mailServer = GetText(commandItem, "mail server", args);
          var subject = GetText(commandItem, "subject", args);
          var message = GetText(commandItem, "message", args);

          Error.Assert(to.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
          Error.Assert(from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
          Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);

          var smtpClient = string.IsNullOrWhiteSpace(mailServer)
          ? new SmtpClient()
          : new SmtpClient(mailServer);
          smtpClient.Send(new MailMessage(from, to)

          Subject = subject,
          Body = message
          );


          public string GetText(Item commandItem, string field, WorkflowPipelineArgs args)

          var text = commandItem[field];
          return text.Length > 0 ? ReplaceVariables(text, args) : string.Empty;


          private static string ReplaceVariables(string text, WorkflowPipelineArgs args)

          text = text.Replace("$itemUrl$", MediaUrl(args.DataItem));
          return text;


          private static string MediaUrl(Item item)

          if (item == null) return string.Empty;

          if (!item.Paths.IsMediaItem) return string.Empty;

          var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
          mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL);
          return mediaUrl;





          Code inspired by this blog post: https://jeffreyrondeau.wordpress.com/2015/02/25/extending-sitecore-workflow-email-action/



          You need to tweak a bit the code because you need to replace "To" field with email addresses from your subscribers list.






          share|improve this answer
















          • 1




            SPE can also be used!
            – Michael West
            1 hour ago














          up vote
          3
          down vote













          I would use Workflow in your case.



          You need to create and assign different workflow for document templates on their standard values to make this working.



          There is an "Email action" OOTB that you can use in your workflow to send emails but you need to create custom class to send emails to your subscribed list.



          Just add this action after Auto Publish to your workflow like this and fill in the fields:



          enter image description here



          Insert text into Message field. Something like:




          We have new document for for! Check it out here: $itemUrl$




          Change Type field especially to your custom class definition:



          enter image description here



          Use Your_namespace_goes_here.SubscribersEmailAction, Your_assembly_name_goes_here notation in Type field. SubscribersEmailAction is name of class below.



          SubscribersEmailAction Class could be something similar to this code:



          using System.Net.Mail;
          using Sitecore.Data.Items;
          using Sitecore.Diagnostics;
          using Sitecore.Workflows.Simple;
          using Sitecore.Links;

          namespace Your_namespace_goes_here

          public class SubscribersEmailAction

          public void Process(WorkflowPipelineArgs args)

          Assert.ArgumentNotNull(args, "args");
          var processorItem = args.ProcessorItem;
          if (processorItem == null)
          return;

          var commandItem = processorItem.InnerItem;
          var fullPath = commandItem.Paths.FullPath;
          var from = GetText(commandItem, "from", args);
          var to = GetText(commandItem, "to", args);
          var mailServer = GetText(commandItem, "mail server", args);
          var subject = GetText(commandItem, "subject", args);
          var message = GetText(commandItem, "message", args);

          Error.Assert(to.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
          Error.Assert(from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
          Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);

          var smtpClient = string.IsNullOrWhiteSpace(mailServer)
          ? new SmtpClient()
          : new SmtpClient(mailServer);
          smtpClient.Send(new MailMessage(from, to)

          Subject = subject,
          Body = message
          );


          public string GetText(Item commandItem, string field, WorkflowPipelineArgs args)

          var text = commandItem[field];
          return text.Length > 0 ? ReplaceVariables(text, args) : string.Empty;


          private static string ReplaceVariables(string text, WorkflowPipelineArgs args)

          text = text.Replace("$itemUrl$", MediaUrl(args.DataItem));
          return text;


          private static string MediaUrl(Item item)

          if (item == null) return string.Empty;

          if (!item.Paths.IsMediaItem) return string.Empty;

          var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
          mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL);
          return mediaUrl;





          Code inspired by this blog post: https://jeffreyrondeau.wordpress.com/2015/02/25/extending-sitecore-workflow-email-action/



          You need to tweak a bit the code because you need to replace "To" field with email addresses from your subscribers list.






          share|improve this answer
















          • 1




            SPE can also be used!
            – Michael West
            1 hour ago












          up vote
          3
          down vote










          up vote
          3
          down vote









          I would use Workflow in your case.



          You need to create and assign different workflow for document templates on their standard values to make this working.



          There is an "Email action" OOTB that you can use in your workflow to send emails but you need to create custom class to send emails to your subscribed list.



          Just add this action after Auto Publish to your workflow like this and fill in the fields:



          enter image description here



          Insert text into Message field. Something like:




          We have new document for for! Check it out here: $itemUrl$




          Change Type field especially to your custom class definition:



          enter image description here



          Use Your_namespace_goes_here.SubscribersEmailAction, Your_assembly_name_goes_here notation in Type field. SubscribersEmailAction is name of class below.



          SubscribersEmailAction Class could be something similar to this code:



          using System.Net.Mail;
          using Sitecore.Data.Items;
          using Sitecore.Diagnostics;
          using Sitecore.Workflows.Simple;
          using Sitecore.Links;

          namespace Your_namespace_goes_here

          public class SubscribersEmailAction

          public void Process(WorkflowPipelineArgs args)

          Assert.ArgumentNotNull(args, "args");
          var processorItem = args.ProcessorItem;
          if (processorItem == null)
          return;

          var commandItem = processorItem.InnerItem;
          var fullPath = commandItem.Paths.FullPath;
          var from = GetText(commandItem, "from", args);
          var to = GetText(commandItem, "to", args);
          var mailServer = GetText(commandItem, "mail server", args);
          var subject = GetText(commandItem, "subject", args);
          var message = GetText(commandItem, "message", args);

          Error.Assert(to.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
          Error.Assert(from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
          Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);

          var smtpClient = string.IsNullOrWhiteSpace(mailServer)
          ? new SmtpClient()
          : new SmtpClient(mailServer);
          smtpClient.Send(new MailMessage(from, to)

          Subject = subject,
          Body = message
          );


          public string GetText(Item commandItem, string field, WorkflowPipelineArgs args)

          var text = commandItem[field];
          return text.Length > 0 ? ReplaceVariables(text, args) : string.Empty;


          private static string ReplaceVariables(string text, WorkflowPipelineArgs args)

          text = text.Replace("$itemUrl$", MediaUrl(args.DataItem));
          return text;


          private static string MediaUrl(Item item)

          if (item == null) return string.Empty;

          if (!item.Paths.IsMediaItem) return string.Empty;

          var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
          mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL);
          return mediaUrl;





          Code inspired by this blog post: https://jeffreyrondeau.wordpress.com/2015/02/25/extending-sitecore-workflow-email-action/



          You need to tweak a bit the code because you need to replace "To" field with email addresses from your subscribers list.






          share|improve this answer












          I would use Workflow in your case.



          You need to create and assign different workflow for document templates on their standard values to make this working.



          There is an "Email action" OOTB that you can use in your workflow to send emails but you need to create custom class to send emails to your subscribed list.



          Just add this action after Auto Publish to your workflow like this and fill in the fields:



          enter image description here



          Insert text into Message field. Something like:




          We have new document for for! Check it out here: $itemUrl$




          Change Type field especially to your custom class definition:



          enter image description here



          Use Your_namespace_goes_here.SubscribersEmailAction, Your_assembly_name_goes_here notation in Type field. SubscribersEmailAction is name of class below.



          SubscribersEmailAction Class could be something similar to this code:



          using System.Net.Mail;
          using Sitecore.Data.Items;
          using Sitecore.Diagnostics;
          using Sitecore.Workflows.Simple;
          using Sitecore.Links;

          namespace Your_namespace_goes_here

          public class SubscribersEmailAction

          public void Process(WorkflowPipelineArgs args)

          Assert.ArgumentNotNull(args, "args");
          var processorItem = args.ProcessorItem;
          if (processorItem == null)
          return;

          var commandItem = processorItem.InnerItem;
          var fullPath = commandItem.Paths.FullPath;
          var from = GetText(commandItem, "from", args);
          var to = GetText(commandItem, "to", args);
          var mailServer = GetText(commandItem, "mail server", args);
          var subject = GetText(commandItem, "subject", args);
          var message = GetText(commandItem, "message", args);

          Error.Assert(to.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
          Error.Assert(from.Length > 0, "The 'From' field is not specified in the mail action item: " + fullPath);
          Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);

          var smtpClient = string.IsNullOrWhiteSpace(mailServer)
          ? new SmtpClient()
          : new SmtpClient(mailServer);
          smtpClient.Send(new MailMessage(from, to)

          Subject = subject,
          Body = message
          );


          public string GetText(Item commandItem, string field, WorkflowPipelineArgs args)

          var text = commandItem[field];
          return text.Length > 0 ? ReplaceVariables(text, args) : string.Empty;


          private static string ReplaceVariables(string text, WorkflowPipelineArgs args)

          text = text.Replace("$itemUrl$", MediaUrl(args.DataItem));
          return text;


          private static string MediaUrl(Item item)

          if (item == null) return string.Empty;

          if (!item.Paths.IsMediaItem) return string.Empty;

          var theURL = Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
          mediaUrl = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(theURL);
          return mediaUrl;





          Code inspired by this blog post: https://jeffreyrondeau.wordpress.com/2015/02/25/extending-sitecore-workflow-email-action/



          You need to tweak a bit the code because you need to replace "To" field with email addresses from your subscribers list.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Peter Prochazka

          3,8131734




          3,8131734







          • 1




            SPE can also be used!
            – Michael West
            1 hour ago












          • 1




            SPE can also be used!
            – Michael West
            1 hour ago







          1




          1




          SPE can also be used!
          – Michael West
          1 hour ago




          SPE can also be used!
          – Michael West
          1 hour ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f14810%2femail-notifications-to-all-subscribers-when-the-new-document-is-published%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke