Intro
By default the tokens in Sitecore's workflow Email Action only provides access to the item's path ($itemPath$), language ($itemLangauge$) and version ($itemVersion). Users often want to customize their workflow notifications to be more meaningful (more tokens & dynamic text). Let's see how we can make that happen.
Code:
As with many things in Sitecore, it's suprisingly easy to create your own tokens. You just need to know where to start. We're going to replace the default Email Action class. Here's the skeleton:
Class to customize Sitecore Email Actions
Look at ReplaceVariables() on line 50. Name your token and call String.Replace() to replace them. Notice in the Process() method that GetText() is used when reading each field. This allows your tokens to be used in your Email Action's To, From, Subject and Message fields.
In addition to adding tokens, you may want to add conditional logic to create more dynamic email messages. With the code wide open there really is no limit to what you can accomplish.
Configuration
Very little.
- Find an existing Email Action in your workflow or navigate to the Email Action's standard values at /sitecore/templates/System/Workflow/Email Action.
- Change the Type field to point to your class and assembly.
- Use your new tokens in the To, From, Title and Message field on your Email Action item.
Summary
Fishtank has a released an Enhanced Email Action module which is based on this technique. It has tokens for the author's name, their comments and a preview URL. While we'll continue to improve up on it, we hope this code gives you all you need to get started on your own.
The NVelocity templating-engine could also be implemented to customize the tokens in your workflow emails. For very complex needs it can be worth a look. However, we prefer the small footprint and precise nature of the approach shown above. With a few custom functions and some logic, it's simple to accomplish almost anything .
Thanks for reading!