PandaTech.MailHelper 2.0.1

Suggested Alternatives

Pandatech.Communicator

Additional Details

Please refer to our new package which has extended and better support Pandatech.Communicator

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package PandaTech.MailHelper --version 2.0.1                
NuGet\Install-Package PandaTech.MailHelper -Version 2.0.1                
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="PandaTech.MailHelper" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PandaTech.MailHelper --version 2.0.1                
#r "nuget: PandaTech.MailHelper, 2.0.1"                
#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.
// 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 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. 
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

.net 8 update