This is a Markdown custom template renderer for FluentEmail
It utilises the ITemplateRenderer interface exposed by FluentEmail to hook in custom template renderers and supports full model binding as available in the default Razor renderer.
Markdown parsing is done by MarkdownDeep
Available on NuGet:
PM> Install-Package FluentEmail.Markdown
var email = Email
.From("[email protected]")
.To("[email protected]")
.Subject("woo nuget")
.UsingTemplateEngine(new MarkdownRenderer()) // Hook in this renderer -- IMPORTANT!!: This needs be set before the next line below
.UsingTemplateFromFile(@"~/test.md", new { Name = "John Smith", Numbers = new string[] { "1", "2", "3" } });
// You can also set the default renderer so all Email instances will use this renderer by doing the following:
// Set global renderer to use (usually in App init):
Email.DefaultRenderer = new MarkdownRenderer();
// Use FluentEmail without the need to call UsingTemplateEngine() each time
var email = Email
.From("[email protected]")
.To("[email protected]")
.Subject("woo nuget")
.UsingTemplateFromFile(@"~/test.md", new { Name = "John Smith", Numbers = new string[] { "1", "2", "3" } });
test.md:
# Heading 1
This is a [Markdown](http://mouapp.com) page
1. one
2. two
3. three
You can also bind to Model
Name: @Model.Name
Numbers:
@foreach (i in Model.Numbers) {
@: - Number: @i
}
The current date is: @DateTime.Now
This will be the rendered output (the Message.Body):
<h1>Heading 1</h1>
<p>This is a <a href="http://mouapp.com">Markdown</a> page</p>
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>
<p>You can also bind to Model</p>
<p>Name: John Smith</p>
<p>Numbers:</p>
<ul>
<li>Number: 1 </li>
<li>Number: 2 </li>
<li>Number: 3 </li>
</ul>
<p>The current date is: 04/08/2014 10:52:33 PM</p>
Note the @foreach syntax above. It follows standard Razor conventions. This renderer actually does a Razor parse on the raw template text first to resolve all model bindings, then depending on the isHtml
flag, will do the Markdown parsing.