I am using Postal to render MVC Razor views and send them via email. I have a custom CSS that I have defined specifically for the email views. Currently I am including them
Upvoted Paul d'Aoust's answer, but I found this version of his helper method to work a little better for me (wouldn't try to encode things like quotes in the CSS):
public static class CssHelper
{
public static IHtmlString EmbedCss(this HtmlHelper htmlHelper, string path)
{
// take a path that starts with "~" and map it to the filesystem.
var cssFilePath = HttpContext.Current.Server.MapPath(path);
// load the contents of that file
try
{
var cssText = File.ReadAllText(cssFilePath);
return htmlHelper.Raw("");
}
catch
{
// return nothing if we can't read the file for any reason
return null;
}
}
}