A Complete Step-by-Step Tutorial for Beginners
Email verification is an essential step in modern applications. It ensures that users provide valid email addresses, reduces spam registrations, and improves security. While sending plain text emails is simple, using HTML email templates enhances user experience by allowing styled content, logos, buttons, and better formatting.
In this tutorial, we will create a full email verification system using:
ASP.NET Core Web API
SQL Server
Angular Frontend (optional for verification page)
HTML email templates
Token-based email verification workflow
We will explain each step clearly with practical examples.
What You Will Build
User registration system
Backend generates a unique verification token
Email is sent using HTML templates with a verification link
User clicks the verification link
Backend verifies the token and marks the user as verified
Angular frontend displays success or error message
This workflow is professional and used in production applications like Gmail, Microsoft, and online banking.
Why HTML Email Templates Are Important
Using HTML templates allows:
Rich content like logos, buttons, and colors
Clear call-to-action for verification
Better mobile compatibility
Branding consistency
Improved user engagement
Part 1: Backend Implementation (ASP.NET Core)
Step 1: Update User Model
File: Models/User.cs
public class User
{
public int Id { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public string PasswordHash { get; set; }
public bool EmailVerified { get; set; } = false;
public string VerificationToken { get; set; }
public DateTime? VerifiedAt { get; set; }
}
Step 2: Generate Verification Token
Create a helper class:
using System.Security.Cryptography;
public static class TokenGenerator
{
public static string GenerateToken()
{
return Convert.ToHexString(RandomNumberGenerator.GetBytes(32));
}
}
Step 3: Create Email Service Using HTML Templates
Install MailKit and MimeKit for sending HTML emails:
dotnet add package MailKit
File: Services/EmailService.cs
using MailKit.Net.Smtp;
using MimeKit;
public class EmailService
{
private readonly IConfiguration _config;
public EmailService(IConfiguration config)
{
_config = config;
}
public async Task SendVerificationEmail(string toEmail, string userName, string token)
{
var verifyUrl = $"{_config["App:BaseUrl"]}/verify-email?token={token}";
// Load HTML template
var template = File.ReadAllText("EmailTemplates/VerifyEmailTemplate.html");
template = template.Replace("{{UserName}}", userName)
.Replace("{{VerifyUrl}}", verifyUrl);
var email = new MimeMessage();
email.From.Add(MailboxAddress.Parse(_config["Email:From"]));
email.To.Add(MailboxAddress.Parse(toEmail));
email.Subject = "Verify Your Email";
var bodyBuilder = new BodyBuilder
{
HtmlBody = template
};
email.Body = bodyBuilder.ToMessageBody();
using var smtp = new SmtpClient();
await smtp.ConnectAsync(_config["Email:SmtpServer"], int.Parse(_config["Email:Port"]), true);
await smtp.AuthenticateAsync(_config["Email:Username"], _config["Email:Password"]);
await smtp.SendAsync(email);
await smtp.DisconnectAsync(true);
}
}
Step 4: Create HTML Template
Folder: EmailTemplates/VerifyEmailTemplate.html

Join the conversation! Your thoughts help the community grow.