Skip to content

Instantly share code, notes, and snippets.

@lukencode
Created May 21, 2013 06:27
Show Gist options
  • Save lukencode/5617855 to your computer and use it in GitHub Desktop.
Save lukencode/5617855 to your computer and use it in GitHub Desktop.
Embedded tempate
/// <summary>
/// Adds template to email from embedded resource
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="path">Path the the embedded resource eg [YourAssembly].[YourResourceFolder].[YourFilename.txt]</param>
/// <param name="model">Model for the template</param>
/// <param name="isHtml">True if Body is HTML, false for plain text (Optional)</param>
/// <param name="assembly">The assembly your resource is in. Defaults to calling assembly.</param>
/// <returns></returns>
public Email UsingTemplateFromEmbedded<T>(string path, T model, bool isHtml = true, Assembly assembly = null)
{
CheckRenderer();
assembly = assembly ?? Assembly.GetCallingAssembly();
var template = EmbeddedResourceHelper.GetResourceAsString(assembly, path);
var result = _renderer.Parse(template, model, isHtml);
Message.Body = result;
Message.IsBodyHtml = isHtml;
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment