Mindfire.RazorEmail.Identity 1.0.1

dotnet add package Mindfire.RazorEmail.Identity --version 1.0.1
                    
NuGet\Install-Package Mindfire.RazorEmail.Identity -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mindfire.RazorEmail.Identity" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mindfire.RazorEmail.Identity" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Mindfire.RazorEmail.Identity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mindfire.RazorEmail.Identity --version 1.0.1
                    
#r "nuget: Mindfire.RazorEmail.Identity, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mindfire.RazorEmail.Identity@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mindfire.RazorEmail.Identity&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Mindfire.RazorEmail.Identity&version=1.0.1
                    
Install as a Cake Tool

Mindfire.RazorEmail.Identity

ASP.NET Core Identity email via Mindfire.RazorEmail. AddIdentityRazorEmail replaces the scaffolded no-op IEmailSender<TUser> and sends confirm-email, password-reset link, and password-reset code messages with Razor templates.

The default templates are copied into the project under EmailTemplates and are used without an extra path setting. Supply the mail settings and the messages send.

Quick start

builder.Services.AddIdentityRazorEmail<ApplicationUser>(builder.Configuration);
builder.Services.AddRazorEmailMailKit();

AddIdentityRazorEmail registers Razor email and the Identity sender. AddRazorEmailMailKit is the SMTP transport. Register a different IEmailTransport instead when mail should go through another provider.

{
	"RazorEmail": {
		"FromName": "Your App",
		"FromAddress": "noreply@example.com",
		"SmtpHost": "smtp.example.com",
		"SmtpPort": 587,
		"SmtpUseSsl": true
	}
}

FromAddress is required. SmtpHost is required when MailKit is registered. Leave SmtpPassword empty in source control and load it from user secrets or the environment. FromName is the product name in the default templates. With FromName set to Contoso, the confirm message says "your Contoso account". When FromName is empty, the templates say "your account" and the header says "Account".

You do not set a template path. The sender looks in EmailTemplates on its own. RazorEmail:TemplatesPath still defaults to email for any other messages you add; a complete folder there overrides the same message name under EmailTemplates.

Templates in the project

On the first build, if the project does not already have an EmailTemplates folder, the package copies this tree into the project:

EmailTemplates/
  Shared/
    _Layout.cshtml
  Confirm Email/
    email.cshtml
    email.txt.cshtml
    email-settings.json
  Reset Password/
    email.cshtml
    email.txt.cshtml
    email-settings.json
  Reset Password Code/
    email.cshtml
    email.txt.cshtml
    email-settings.json

Edit those files to change wording, colors, or layout. The next package update does not overwrite a folder that is already there. Add a culture file beside the defaults and it stays.

The build also copies EmailTemplates to the output and publish directories. RazorLight reads the files from disk. During dotnet run the content root is the project directory. A published app uses the publish directory, so the copy is what the deployed app renders. The .cshtml files are not compiled as Blazor or MVC views.

The three Identity calls map to those folders:

Identity method Folder Model
SendConfirmationLinkAsync Confirm Email ConfirmEmailModel
SendPasswordResetLinkAsync Reset Password ResetPasswordEmailModel
SendPasswordResetCodeAsync Reset Password Code ResetPasswordCodeEmailModel
public sealed record ConfirmEmailModel(string? DisplayName, string ConfirmationUrl, string? ProductName = null);
public sealed record ResetPasswordEmailModel(string? DisplayName, string ResetUrl, string? ProductName = null);
public sealed record ResetPasswordCodeEmailModel(string? DisplayName, string Code, string? ProductName = null);

ProductName is RazorEmail:FromName. When TUser has a public string or string? property named DisplayName, the greeting uses it. Otherwise the greeting is "Hello,".

The sender passes CultureInfo.CurrentUICulture, so a request whose UI culture is es-MX looks for the Mexican Spanish files described below.

Shared/_Layout.cshtml is the shell around every HTML body. The header prints ProductName. Each body can define two optional sections:

  • Preheader is hidden preview text shown by some inbox lists.
  • FooterReason is the line that says why the message was sent. The layout always adds "If you did not request this, you can ignore this message."

Change the default copy

Open EmailTemplates/Confirm Email/email.cshtml and edit the sentence or the button. The plain-text twin is email.txt.cshtml. The subject is Subject in email-settings.json.

{
	"Subject": "Confirm your email"
}

Keep the @model type. The sender constructs that model. Razor encodes @Model.ConfirmationUrl, so leave the URL raw.

Add a culture

Culture files live in the same folder. The culture name goes in the file name, not in a new folder.

To translate the confirm message for Spanish, and to give Mexico its own HTML body, add:

EmailTemplates/Confirm Email/
  email.cshtml
  email.txt.cshtml
  email.es.cshtml
  email.es.txt.cshtml
  email.es-MX.cshtml
  email-settings.json

email.es.cshtml is Spanish for any region that does not have a more specific file. email.es-MX.cshtml is the Mexican Spanish HTML only. This example has no email.es-MX.txt.cshtml, so the plain-text body falls back on its own.

@using Mindfire.RazorEmail.Identity
@model ConfirmEmailModel
@{
	Layout = "Shared/_Layout.cshtml";
	var account = string.IsNullOrWhiteSpace(Model.ProductName) ? "tu cuenta" : $"tu cuenta de {Model.ProductName}";
}
<p>Hola@(string.IsNullOrWhiteSpace(Model.DisplayName) ? "," : $" {Model.DisplayName},")</p>
<p>Confirma @account con el botón de abajo.</p>

Subjects use the same culture names:

{
	"Subject": "Confirm your email",
	"Subjects": {
		"es": "Confirma tu correo",
		"es-MX": "Confirma tu correo electrónico"
	}
}

Fallback

HTML, plain text, and the subject are resolved separately. For a UI culture of es-MX the order is es-MX, then the parent es, then the default file or Subject.

Piece es-MX file present Only es present Neither present
HTML email.es-MX.cshtml email.es.cshtml email.cshtml
Plain text email.es-MX.txt.cshtml email.es.txt.cshtml email.txt.cshtml
Subject Subjects["es-MX"] Subjects["es"] Subject

es-ES uses the es files when there is no es-ES file, because es is the parent of both es-MX and es-ES. A culture with no file and no parent file uses the default English templates that ship in the package.

The same rules apply to Reset Password and Reset Password Code. A culture file in one folder does not affect the others.

See the Mindfire.RazorEmail README for building a message that is not one of these three, including layouts and a folder you send yourself through RazorEmailGenerator<T>.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 58 11/19/2026
1.0.0 59 11/19/2026