TokenMail for .NET converts tokens in plain-text files into values you define.

Lightweight implementation of a template email helper class.

Can retrieve any file on disk and parse it for any tokens you specify (eg. "$FIRST_NAME" or "##FIRST_NAME##") and replace them with their corresponding values.

Has one simple Send() method which accepts the recipient's email address, sender's email address, a list of CC and/or BCC addresses (optional) and the subject line, together with the dictionary containing your key/value pairs representing the values to find and replace.


  • NEW! Now supports loading a template from a URL
  • Supports HTML & plain-text email
  • Can do find/replace on just about any plain-text file format
  • Small footprint, easily extended
  • Let your end-users manage the email templates themselves; they're just plain-text files on disk - so can be loaded into your favourite rich text editor

Usage example:

// Fetch template body from disk
var template = TemplateHelper.GetEmailTemplate("D:\Path\File.htm"); // or GetEmailTemplate("");

// Add any tokens you want to find/replace within your template file
var tokens = new Dictionary {{"##FIRSTNAME##", "Richard"}, {"##LASTNAME##", "Parker"}};

// Specify addresses (CC and BCC are optional)
var to = new MailAddress("");
var fr = new MailAddress("");
var cc = new List() {new MailAddress(""), new MailAddress("")};
var bcc = new List() {new MailAddress("")};
var attachments = new AttachmentCollection();
attachments.Add(span style="color: blue;">new Attachment("D:\myfile.htm"));

// Send the mail TemplateHelper.Send(to, fr, cc, bcc, "##FIRSTNAME##, thanks for registering!", tokens, template, attachments, true);

NuGet Package:

This library is also now available on NuGet, with thanks to @benjaminhowarth (aka CodeGecko here on CodePlex). We'll try to keep the NuGet package in synch with what is published here on CodePlex.

NuGet package: TokenMail

Last edited Jul 11, 2011 at 9:39 AM by codegecko, version 22