RSS feed icon BTB Shadow Man logo


Tell me what you think about my website, I really want to know.

Your feedback is appreciated!

Average Rating: 
Whole StarWhole StarWhole StarWhole StarHalf Star

Total number of ratings: 27

Email Template Framework - Version 2.5

Email Template FrameworkNew Version 2.5 - 10 February 2011
The new version of the framework now has the ability to define a Reply To email address. This feature was suggested and coded by James Traxler So a big thank you to James for contributing this to the project :)

The complete C# source code is included under a BSD license.

What Is It?
It's a simple framework written in C# that allow email messages to be composed in a XML file that can then be merged with data at runtime and sent to a recipient.
Put another way, it allows you to create a web application that sends emails without having to hard code the email message in your assembly.

5 Reasons to Use It

  1. Email messages are created outside your program/assembly in standard XML files.
  2. Merge data into your email at runtime
  3. Send the same email to multiple recipients
  4. Able to send emails as plain or HTML format
  5. Easy integration with your application

Here is a really simple example of an email template.

<?xml version="1.0" encoding="utf-8" ?>
<template:emailTemplate application="example application" version="2.0"
<template:name>User Registered</template:name>
<template:description>Email template used as an example, sends a welcome email to new registered
users along with there details</template:description>
 <template:subject>Welcome to dummySite</template:subject>
 <template:body><user:userData name="user_name" mandatory="true" />
Thank you for registering with, our account details are shown below
<user:userDataDictionary mandatory="true" name="userAccountDetails">
  <user:itemSeparator>:- </user:itemSeparator>
 </user:userDataDictionary> Regards Site Administrator

The template is created in XML and contains markup elements which are replaced with data prior to sending the email.
Sample C# code used to populate the template and send the email is shown below.

using System;
using System.Collections;
using System.Collections.Specialized;

using EmailTemplateProcessor;

namespace Email_Template_Example
    /// <summary>
    /// Example used to send a sample email using email
    ///template framework
    /// </summary>
    class Example
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
            //normally the data would come from a database,
            //here we will load the
            //data into the hashtable ourselves
            Hashtable data = new Hashtable();
            data.Add("user_name", "John Smith");

            //create some sample user account data in a
            OrderedDictionary userAccount = new OrderedDictionary();
            userAccount.Add("Username", "smithj");
            userAccount.Add("Password", "secret");
            userAccount.Add("Street", "1 New Town");
            userAccount.Add("City", "London");
            userAccount.Add("Postcode", "L1 3RG");

            //add the userdetails hashtable to data
            data.Add("userAccountDetails", userAccount);

            //merge the template with the data
            EmailTemplate mailTemplate = new EmailTemplate( System.Environment.CurrentDirectory, @"\mailTemplate\simpleListTemplate.xml");
            //since we are sending this email to one address we
            //can use the new property
            mailTemplate.ToSingleAddress = ""; //add your address
                                         //here to get this to work

            //other wise we could call this method with
            //a string array
            //holding all the receipt email address
            //mailTemplate.To = new string[] {"",             // "...", "..."};
            //this would come the database in real world

            EmailProcessor processor = new EmailProcessor("localhost");



The resulting email received by the user.


Sample email screenshot

Download the zip file containing the assembly, source code and documentation here.

Privacy PolicyTerms and ConditionsCopyright © 2005 - 2012