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.

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.