Looking to use Rules Module for Automating Configurable Emails

Topics: Customizing Orchard, General, Writing modules
Nov 11, 2011 at 1:42 AM

We are wanting to have emails based on email templates that can be created from the admin interface to be sent out based on definable events. I noticed that there is an email module and an email rules module. However when I enabled them and went to the rules section from the admin menu I noticed that by default there are no events that can be added to a rule which would imply to me that there is no way to trigger the events. I looked in the code and nothing implements the IEventProvider interface which I assume would provide events for rules. I'm guessing this is an unfinished feature? Or is there any examples of how I could use this system to send triggered templated emails?

Coordinator
Nov 11, 2011 at 1:50 AM

It is a finished feature but you need to enable the modules that expose the events you need.

Nov 11, 2011 at 10:19 AM
Edited Nov 11, 2011 at 10:22 AM

Could you please give a tip about writing modules that expose the events? Is there such modules in the gallery?

Nov 11, 2011 at 11:41 AM

A number of Orchard's modules now have a "Rules" feature which expose events and actions. Look at "Content", "Comments", "Email"...

Nov 11, 2011 at 1:08 PM

All the modules you mentioned have already installed. But why in this case the Events section is empty on the add new rule page?

Nov 11, 2011 at 1:35 PM

The Rules are in separate features - so you have to enable the feature called "Content Rules", etc. Then the events/actions will start to appear.

Nov 11, 2011 at 2:21 PM

It really works fine. Thanks a lot!

Nov 12, 2011 at 1:25 AM
Edited Nov 12, 2011 at 1:25 AM

Ok I found the events in the content module. But I can't seem to figure out how an event is fired. Do you just have to call a certain function and that signals to orchard that a certain event has fired?

Nov 12, 2011 at 11:25 AM

For example the Content Rules are triggered in Orchard.Web\Core\Contents\Handlers\RulesHandler.cs

Nov 14, 2011 at 7:04 PM

Ok I see. So I just need to call the rulesManager.TriggerEvent and then give it a category and type string that match what is put in my IEventProvider. The Category string matching the for part and the Type string matching the element part. So for the actions is the dynamic context the same for the events and the actions? Allowing me to pass information from the events to the actions like if I wanted to have a message appear on all content type creation but have it tailored to the specific content type that was created would I have that information available on the dynamic context of the action I created?

Nov 14, 2011 at 7:24 PM

Well I'm not 100% but I assume so (otherwise the dynamic context would be next to useless!)