Tolitech.Infrastructure.Mail
1.0.0-preview.5
dotnet add package Tolitech.Infrastructure.Mail --version 1.0.0-preview.5
NuGet\Install-Package Tolitech.Infrastructure.Mail -Version 1.0.0-preview.5
<PackageReference Include="Tolitech.Infrastructure.Mail" Version="1.0.0-preview.5" />
<PackageVersion Include="Tolitech.Infrastructure.Mail" Version="1.0.0-preview.5" />
<PackageReference Include="Tolitech.Infrastructure.Mail" />
paket add Tolitech.Infrastructure.Mail --version 1.0.0-preview.5
#r "nuget: Tolitech.Infrastructure.Mail, 1.0.0-preview.5"
#:package Tolitech.Infrastructure.Mail@1.0.0-preview.5
#addin nuget:?package=Tolitech.Infrastructure.Mail&version=1.0.0-preview.5&prerelease
#tool nuget:?package=Tolitech.Infrastructure.Mail&version=1.0.0-preview.5&prerelease
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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Logging (>= 9.0.6)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.6)
- Microsoft.Extensions.Options.DataAnnotations (>= 9.0.6)
- Tolitech.Application.Mail (>= 1.0.0-preview.4)
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 |