Tolitech.CleanArchitecture.Infrastructure.Mail
1.0.0-alpha03
dotnet add package Tolitech.CleanArchitecture.Infrastructure.Mail --version 1.0.0-alpha03
NuGet\Install-Package Tolitech.CleanArchitecture.Infrastructure.Mail -Version 1.0.0-alpha03
<PackageReference Include="Tolitech.CleanArchitecture.Infrastructure.Mail" Version="1.0.0-alpha03" />
paket add Tolitech.CleanArchitecture.Infrastructure.Mail --version 1.0.0-alpha03
#r "nuget: Tolitech.CleanArchitecture.Infrastructure.Mail, 1.0.0-alpha03"
// Install Tolitech.CleanArchitecture.Infrastructure.Mail as a Cake Addin #addin nuget:?package=Tolitech.CleanArchitecture.Infrastructure.Mail&version=1.0.0-alpha03&prerelease // Install Tolitech.CleanArchitecture.Infrastructure.Mail as a Cake Tool #tool nuget:?package=Tolitech.CleanArchitecture.Infrastructure.Mail&version=1.0.0-alpha03&prerelease
CleanArchitecture.Infrastructure.Mail
Overview
Tolitech.CleanArchitecture.Infrastructure.Mail is a comprehensive .NET library designed to simplify the configuration and management of SMTP email settings. It provides robust support for sending emails asynchronously, managing SMTP client configurations, and handling logging for email-related operations. This library is ideal for developers looking to integrate reliable and efficient email sending capabilities into their .NET applications.
Features
- SMTP Configuration: Easy configuration of SMTP settings.
- Asynchronous Email Sending: Support for sending emails asynchronously to improve application performance.
- Customizable Sender: Option to specify a custom sender address or use the default address.
- CC and BCC Support: Easily include CC and BCC recipients.
- HTML Template Support: Retrieve and use HTML templates for email content.
- Error Logging: Detailed logging for email sending errors and HTML template retrieval issues.
Installation
To install Tolitech.CleanArchitecture.Infrastructure.Mail, use the following command in your .NET project:
dotnet add package Tolitech.CleanArchitecture.Infrastructure.Mail
Getting Started
Here�s a quick guide to get you started with Tolitech.CleanArchitecture.Infrastructure.Mail:
Step 1: Configure SMTP Settings
First, configure your SMTP settings in your application's configuration file.
{
"SmtpSettings": {
"Host": "smtp.your-email-provider.com",
"Port": 587,
"From": "your-email@example.com",
"Username": "your-email@example.com",
"Password": "your-email-password"
}
}
Step 2: Configure Services
Use the ConfigureMail extension method to configure SMTP settings in your service collection.
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.ConfigureMail(configuration);
}
Step 3: Implement the Base Email Service
Create a class that implements the BaseEmailService to send emails.
public class EmailService : BaseEmailService
{
public EmailService(SmtpClient smtpClient, IOptions<SmtpSettings> smtpOptions, ILogger<EmailService> logger)
: base(smtpClient, smtpOptions, logger)
{
}
}
Step 4: Send an Email
Use your EmailService to send an email.
public async Task SendTestEmail(IEmailService emailService)
{
await emailService.SendEmailAsync(
to: "recipient@example.com",
subject: "Test Email",
content: "This is a test email sent using Tolitech.CleanArchitecture.Infrastructure.Mail.",
from: "your-email@example.com"
);
}
Advanced Usage
Sending Emails with CC and BCC
You can easily add CC and BCC recipients to your email.
await emailService.SendEmailAsync(
to: "recipient@example.com",
subject: "Test Email with CC and BCC",
content: "This email includes CC and BCC recipients.",
cc: "cc-recipient@example.com",
bcc: "bcc-recipient@example.com"
string htmlContent = await emailService.GetHtmlTemplateAsync("Templates/EmailTemplate.html");
await emailService.SendEmailAsync(
to: "recipient@example.com",
subject: "Email with HTML Template",
content: htmlContent
);
Error Logging
Tolitech.CleanArchitecture.Infrastructure.Mail provides detailed logging for email sending errors and HTML template retrieval issues, helping you monitor and debug the email sending process effectively.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
- Tolitech.CleanArchitecture.Application.Mail (>= 1.0.0-alpha01)
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-alpha03 | 50 | 7/26/2024 |
1.0.0-alpha02 | 62 | 6/22/2024 |
1.0.0-alpha01 | 49 | 6/21/2024 |