1

I have a requirement to send a email to subscribers once a blog will be available publicly. Requirement is very specific that email will be send only one time when item is created, not on update or multiple publishing. We will use EXM automated campaign to send email through code . I would like to know best approach to track the availability of item in web database and send email.

3

I would use item:created event handler, because this is only fired once, when the item is published. (Publish creates the item in web database). It isn't fired multiple times, even if you create a new version from the item or republish the item instead of smart publish.

 public void OnItemCreated(object sender, EventArgs args)
    {
        Item item = ((Sitecore.Data.Events.ItemCreatedEventArgs)(Event.ExtractParameter(args, 0))).Item;

        if (item == null)
        {
            return;
        }

        if (item.Database.Name == "web")
        {
            // Send your mail
        }
    }

Do not forget to register this at "item:created" event in your config

  • Arvai, unfortunately this code will not work as item create fires only when item get created in master. I didn't find any code/event where i can capture itemcreated event for web database. – user3213640 Apr 25 at 20:55
  • I've tested with Sitecore 9 and it is fired when item created in web database (by a publish). if you tried, can you share your config and your code? and yes, this event is also fired when item is created in master db, but you check the current database is web or master. – Árvai Mihály Apr 26 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.