RG.RazorMail 1.0.3
RG.RazorMail
Render razor view to html and inline css. This library simply wraps RazorLight and PreMailer.Net
Setup
1. Add to service collection
services.AddRazorMail(options => {
options.ViewAssembly = Assembly.GetEntryAssembly();
});
2. Set PreserveCompilationContext to true in your .csproj file
<PropertyGroup>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
3. Set build action of your razor views to EmbeddedResource
4. Use relative path of your razor views as viewName
string html = await _razorMail.RenderAsync("Views/Home/Index.cshtml", model);
Available methods
// Render razor view to string
Task<string> RenderAsync<T>(string viewName, T model);
// Render razor view to string and inline css
Task<string> RenderAndInlineCssAsync<T>(string viewName, T model, string? css = null);
// Inline css only
string InlineCss(string html, string? css = null);
No packages depend on RG.RazorMail.
.NET 8.0
- PreMailer.Net (>= 2.5.0)
- RazorLight (>= 2.3.1)