Sueetie Email Templates came about because we were ramping up to add messaging into a number of Sueetie Member processes and needed a quick and easy way to send out localized email messages. We also designed Sueetie Email Templates to enable other .NET developers to easily modify our templates and add their own template-based notifications to their custom features.
A Working Example of Sueetie Email Templates
One of the first processes we enhanced with the Sueetie Email Template model was Friend Request Notifications, so we will look at that as a working example.
The process of using a Sueetie Email Template works like this:
- We create a new instance of the SueetieEmailTemplate class, passing to it a SueetieEmailType enumerator.
- We populate SueetieEmailTemplate parameters and any SueetieUser data used in parsing a localized email message template.
- We pass the populated SueetieEmailTemplate object to an Asynchronous Email Processing method in our Sueetie.Core.EmailHelper class.
Let’s get back to that working example.
Populating the SueetieEmailTemplate Class
Using the Friend Request process, let’s look at how we start the process of using the SueetieEmailTemplate class. We are (1) Creating a new instance of SueetieEmailTemplate and passing a SueetieEmailType, (2) defining the template parameters used in parsing the localized Template string, and (3) passing the SueetieEmailTemplate to our EmailHelper for processing.
The Localized Template File
We’ll be using the Framework SueetieLocalizer services to retrieve and parse our localized Email Template. All Email Templates are located in /util/languages/LANGUAGE/Templates.xml. Here is the template we’re using for Friend Requests. We’re only sending text messages for Friend Requests so we won’t use the Html option, otherwise it would contain encoded HTML for parsing.
Initiating the Notification Process
Getting the notification party started using Sueetie Email Templates is extremely easy. A single line from the UI layer to the business class (example of which we saw above in populating the template) is all that is required. Here is the line of code which sends a Friends Request.
You’ll notice that we’re using a condition for sending the email unique to the Friends Notification, but the notification itself kicks off with the single Business method call which can be inserted in any Sueetie Application, as it is used here in YetAnotherForum.NET.
The end result of our working example is a simple email sent to the member whose friendship was requested. The emails can of course be as simple or as complex as you need.
Templates and The Developer
Here’s a bonus feature of the Sueetie Email architecture, you can easily set Sueetie to deliver email messages to a local folder on your development machine for testing and development. You set Sueetie Email in local delivery mode by changing two properties in the /Sueetie.config file, SendEmails and LocalEmailPath. There’s a lot more to modifying SMTP delivery, but we’ve taken care of that for you. Simply set SendEmails to "false" and enter where you want your templated emails to be sent. Here’s an example.
Constructing an Email Template Architecture was on our Roadmap for some time, so we’re happy it is now something we can leverage to add more communications and messaging in Sueetie Communities.