Tolitech.Infrastructure.Mail 1.0.0-preview.5

This is a prerelease version of Tolitech.Infrastructure.Mail.
dotnet add package Tolitech.Infrastructure.Mail --version 1.0.0-preview.5
                    
NuGet\Install-Package Tolitech.Infrastructure.Mail -Version 1.0.0-preview.5
                    
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="Tolitech.Infrastructure.Mail" Version="1.0.0-preview.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Infrastructure.Mail" Version="1.0.0-preview.5" />
                    
Directory.Packages.props
<PackageReference Include="Tolitech.Infrastructure.Mail" />
                    
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 Tolitech.Infrastructure.Mail --version 1.0.0-preview.5
                    
#r "nuget: Tolitech.Infrastructure.Mail, 1.0.0-preview.5"
                    
#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 Tolitech.Infrastructure.Mail@1.0.0-preview.5
                    
#: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=Tolitech.Infrastructure.Mail&version=1.0.0-preview.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tolitech.Infrastructure.Mail&version=1.0.0-preview.5&prerelease
                    
Install as a Cake Tool

Tolitech.Infrastructure.Mail

A comprehensive .NET library providing essential utilities for sending emails asynchronously. It simplifies SMTP configuration, supports advanced email features, and integrates seamlessly with .NET applications.

Features

  • Easy SMTP configuration
  • Asynchronous email sending
  • Customizable sender address
  • CC and BCC support
  • HTML template support
  • Detailed error logging

Installation

Add the NuGet package to your project:

dotnet add package Tolitech.Infrastructure.Mail

Getting Started

1. Configure SMTP Settings

Add your SMTP settings to your application's configuration (e.g., appsettings.json):

{
  "SmtpSettings": {
    "Host": "smtp.your-email-provider.com",
    "Port": 587,
    "From": "your-email@example.com",
    "Username": "your-email@example.com",
    "Password": "your-email-password"
  }
}

2. Register Services

Use the extension method to register mail services:

using Tolitech.Infrastructure.Mail;

var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureMail(builder.Configuration);

3. Implement the Email Service

Create a class that inherits from BaseEmailService:

public class EmailService : BaseEmailService
{
    public EmailService(SmtpClient smtpClient, IOptions<SmtpSettings> smtpOptions, ILogger<EmailService> logger)
        : base(smtpClient, smtpOptions, logger)
    {
    }
}

4. Send an Email

Use your service to send an email:

await emailService.SendEmailAsync(
    to: "recipient@example.com",
    subject: "Test Email",
    content: "This is a test email sent using Tolitech.Infrastructure.Mail.",
    from: "your-email@example.com"
);

Advanced Usage

Sending Emails with CC and BCC
await emailService.SendEmailAsync(
    to: "recipient@example.com",
    subject: "Test Email with CC and BCC",
    content: "This email includes CC and BCC recipients.",
    cc: "cc@example.com",
    bcc: "bcc@example.com"
);
Using HTML Templates
string htmlContent = await emailService.GetHtmlTemplateAsync("Templates/EmailTemplate.html");
await emailService.SendEmailAsync(
    to: "recipient@example.com",
    subject: "Email with HTML Template",
    content: htmlContent
);

Error Logging

The library provides detailed logging for email sending errors and template retrieval issues, helping you monitor and debug the process effectively.


Tolitech.Infrastructure.Mail makes email sending in .NET robust, flexible, and easy to integrate.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.0-preview.5 466 7/21/2025
1.0.0-preview.4 120 7/3/2025
1.0.0-preview.3 129 7/3/2025
1.0.0-preview.2 102 12/14/2024
1.0.0-preview.1 75 12/12/2024