Fluent Email now supporting custom template renderers

See an updated (2018) example of sending in .NET core email using FluentEmail.

Fluent Email is a simple wrapper for System.Net.Mail that provides a fluent interface for constructing and sending emails in .Net. It also provides a Razor based template rendering engine. After getting a couple of requests for different renderers I decided to provide an interface in Fluent Email for templating that anyone can implement.

The updated version of fluent email is available as always on nuget and you can find the source on github.

The interface itself is really basic and has just one method:

public interface ITemplateRenderer
{
	string Parse<T>(string template, T model);
}

The default renderer uses the awesome RazorEngine to implement the interface:

public class RazorRenderer : ITemplateRenderer
{
	public string Parse<T>(string template, T model)
	{
		return Razor.Parse<T>(template, model);
	}
}

If you want to use your own renderer all you need to do is implement the ITemplateRenderer interface and call the UsingTemplateEngine method when constructing an email:

var email = Email
		.FromDefault()
		.To("[email protected]")
		.Subject("awesome new fluent email features")
		.UsingTemplateEngine(new CustomTemplateRenderer())
		.UsingTemplate(template, new { Name = "LUKE" })
		.Send();

Here are a couple of the different engines I have seen people using for fluent email (not yet implementing the new interface but hopefully soon). If you have your own implementation leave a comment with a link and I will add it too the list.

👋 Are you an 🇦🇺 Australian developer or IT professional? Go check out my site Australian Technology Jobs - a Premium developer and IT job board and find awesome Australian dev jobs (and people).
Questions or comments? Follow me on twitter!
Follow @lukencode