batteries.Email 1.0.15

dotnet add package batteries.Email --version 1.0.15                
NuGet\Install-Package batteries.Email -Version 1.0.15                
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="batteries.Email" Version="1.0.15" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add batteries.Email --version 1.0.15                
#r "nuget: batteries.Email, 1.0.15"                
#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 batteries.Email as a Cake Addin
#addin nuget:?package=batteries.Email&version=1.0.15

// Install batteries.Email as a Cake Tool
#tool nuget:?package=batteries.Email&version=1.0.15                

NuGet Version

Description

This package contains a useful email service based on MailKit.

Usage

The message bus manager can be used for managing multiple instances of message bus on different locations.

Here is how to use it:

  1. Add the setting binding

    builder.Services.AddOptions<SmtpSettings>()
    .BindConfiguration("MailSettings")
    .ValidateDataAnnotations()
    .ValidateOnStart();
    builder.Services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<SmtpSettings>>().Value);
    
    
  2. Adapt your appsettings.json and include the necessary settings: <small>(remember some provider like gmail enforce the usage of app passwords)</small>

    "MailSettings": {
     "SmtpServer": "smtp.gmail.com",
     "Port": 465,
     "Username": "my-fancy-gmail-account@gmail.com",
     "Password": "xxxx xxxx xxxx xxxx",
     "SenderAddress": "no-reply@no-mail.com",
     "SenderName": "Fancy Service"
    }
    
  3. Add the background service

    builder.Services.AddSingleton<SmtpEmailService>();
    builder.Services.AddSingleton<IHostedService, SmtpEmailService>(serviceProvider => serviceProvider.GetService<SmtpEmailService>());
    builder.Services.AddSingleton<IEmailSender, SmtpEmailService>(serviceProvider => serviceProvider.GetService<SmtpEmailService>());
    
  4. Inject the service (for example in one controller)

    public class DataController : ControllerBase
    {
        private readonly ILogger<DataController> logger;
        private readonly IEmailSender sender;
    
        public DataController(ILogger<DataController> logger, IEmailSender sender)
        {
            this.logger = logger;
            this.sender = sender;
        }
    }
    

OAuth2 and Microsoft Office 356

Preparation:

Follow this guide or the official guide for granting mailbox permission to a service principal.

todo

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
1.0.15 31 1/30/2025
1.0.14 42 1/26/2025
1.0.13 38 1/25/2025