Insights

Customizing Sitecore's Workflow Email Action

A class to create custom tokens and dynamic messages

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.

Screenshot of Email Action item configured

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!

👋 Hey Sitecore Enthusiasts!

Sign up to our bi-weekly newsletter for a bite-sized curation of valuable insight from the Sitecore community.

What’s in it for you?

  • Stay up-to-date with the latest Sitecore news
  • New to Sitecore? Learn tips and tricks to help you navigate this powerful tool
  • Sitecore pro? Expand your skill set and discover troubleshooting tips
  • Browse open careers and opportunities
  • Get a chance to be featured in upcoming editions
  • Learn our secret handshake
  • And more!
Sitecore Snack a newsletter by Fishtank Consulting
 

Meet Dan Cruickshank

President | Sitecore MVP x 11

Dan is the founder of Fishtank. He's a multi-time Sitecore MVP and Coveo MVP award winner. Outside of technology, he is widely considered to be a top 3 father (routinely receiving "Father of the Year" accolades from his family) and past his prime on the basketball court.

Connect with Dan