RG.RazorMail 1.0.2

RG.RazorMail

NuGet .NET

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 7.0

Version Downloads Last updated
2.0.1 1 06/15/2026
1.9.1 1 06/15/2026
1.9.0 1 06/15/2026
1.0.7 1 06/15/2026
1.0.6 1 06/15/2026
1.0.5 1 06/15/2026
1.0.4 1 06/15/2026
1.0.3 1 06/15/2026
1.0.2 1 06/15/2026
1.0.1 1 06/15/2026
1.0.0 1 06/15/2026