RG.RazorMail 1.0.5

RG.RazorMail

NuGet .NET

Render razor view to html and inline css. This library simply wraps RazorLight and PreMailer.Net

Setup

1. For Rendering .cshtml Views

1.1. Add to service collection

services.AddRazorMail(options => {
    options.ViewAssembly = Assembly.GetEntryAssembly();
});

1.2. Set PreserveCompilationContext to true in your .csproj file

<PropertyGroup>
  <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

1.3. Set build action of your razor views to EmbeddedResource

1.4. Use relative path of your razor views as viewName

string html = await _razorMail.RenderAsync("Views/Home/Index.cshtml", model);

2. For Rendering .razor Components

2.1. Add to service collection

services.AddRazorMail();

Available methods

// Render razor view to string
Task<string> RenderAsync<T>(string viewName, T model);

// Render razor component to string
Task<string> RenderComponentAsync<TComponent>(IDictionary<string, object>? parameters);

// Render razor view to string and inline css
Task<string> RenderAndInlineCssAsync<T>(string viewName, T model, string? css = null);

// Render razor component to string and inline css
Task<string> RenderComponentAndInlineCssAsync<TComponent>(IDictionary<string, object>? parameters, string? css = null);

// Inline css only
string InlineCss(string html, string? css = null);

No packages depend on RG.RazorMail.

.NET 8.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