Create an email template in .NET
Download the code example to create email templates in your ASP.NET Core app.
You can learn about the best way to create an email template in .NET, or watch the video.
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
Software
This is the software that will need to be installed onto your machine.
Visual Studio 2026. Version 18.0.0 or above. It will work with the free community version.
.NET 10 SDK. Version 10.0.0 or above.
The application
Open up RoundTheCode.SendEmail.slnx. The solution has three projects:
Application
This is a Razor class library that contains common classes and the Razor view email templates located in Views/Email.
Web
This is an ASP.NET Core Web API.
When it starts, it will load https://localhost:7247/send-email, which will render the order confirmation email template.
You can also open https://localhost:7247/send-email/new-order, which will render the new order email template.
The email content is generated from the views located in Views/Email from the Application project. It's generated as an HTML string using EmailHelper.GetEmailContentAsync, which is also located in the Application project.
Worker
This is a background worker service.
When it starts, it will run the EmailWorker hosted service. This runs every 60 seconds and will render both the order confirmation and new order email templates to the log.
Like the Web project, the email content is generated from the views located in Views/Email from the Application project, and is generated as an HTML string using EmailHelper.GetEmailContentAsync.
Download this code example
Enter your email and we'll send you a download link.
Latest code examples
Download an ASP.NET Core middleware example that covers how to create your own custom middleware and shows how to inject services.
A EF Core example showing how to use Include() to join navigation properties together, when not to use Include() and when you need to configure the join.
Download this code example
Enter your email and we'll send you a download link.