PandaTech.MailHelper
2.0.1
Please refer to our new package which has extended and better support Pandatech.Communicator
dotnet add package PandaTech.MailHelper --version 2.0.1
NuGet\Install-Package PandaTech.MailHelper -Version 2.0.1
<PackageReference Include="PandaTech.MailHelper" Version="2.0.1" />
paket add PandaTech.MailHelper --version 2.0.1
#r "nuget: PandaTech.MailHelper, 2.0.1"
// Install PandaTech.MailHelper as a Cake Addin #addin nuget:?package=PandaTech.MailHelper&version=2.0.1 // Install PandaTech.MailHelper as a Cake Tool #tool nuget:?package=PandaTech.MailHelper&version=2.0.1
PandaTech.MailHelper NuGet
Introduction
This module provides an efficient and scalable way to send emails in .NET applications. It includes a background service for email queuing and sending, SMTP client configuration, and support for attachments.
Prerequisites
- .NET 8.0 or later
- SMTP server credentials
Configuration
To configure the email module, you need to set up the MailServerConfig
in your application settings (
e.g., appsettings.json
). Here is an example configuration:
{
"MailServerConfig": {
"SmtpServer": "smtp.example.com",
"SmtpPort": 587,
"SmtpUser": "your-smtp-username",
"SmtpPassword": "your-smtp-password",
"SmtpFrom": "no-reply@example.com",
"SenderTimerSeconds": 5
}
}
Usage
Adding the Service
First, add the mail service to your application builder in Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.AddMailService(config =>
{
config.SmtpServer = builder.Configuration["MailServerConfig:SmtpServer"];
config.SmtpPort = int.Parse(builder.Configuration["MailServerConfig:SmtpPort"]);
config.SmtpUser = builder.Configuration["MailServerConfig:SmtpUser"];
config.SmtpPassword = builder.Configuration["MailServerConfig:SmtpPassword"];
config.SmtpFrom = builder.Configuration["MailServerConfig:SmtpFrom"];
config.SenderTimerSeconds = int.Parse(builder.Configuration["MailServerConfig:SenderTimerSeconds"]);
});
Sending Emails
To send an email, inject and use the IEmailService
interface:
public class SomeService
{
private readonly IEmailService _emailService;
public SomeService(IEmailService emailService)
{
_emailService = emailService;
}
public async Task SendSampleEmailAsync()
{
var message = new Message
{
To = "recipient@example.com",
Subject = "Email Subject",
Body = "<h1>Email Body</h1>",
Attachments = null // Optional: List of AttachmentData objects
};
await _emailService.SendEmailAsync(message);
}
}
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
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. net9.0 was computed. 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. |
-
net8.0
- Microsoft.AspNetCore.OpenApi (>= 8.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.0)
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 |
---|
.net 8 update