batteries.Email
1.0.15
dotnet add package batteries.Email --version 1.0.15
NuGet\Install-Package batteries.Email -Version 1.0.15
<PackageReference Include="batteries.Email" Version="1.0.15" />
paket add batteries.Email --version 1.0.15
#r "nuget: batteries.Email, 1.0.15"
// 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
batteries.Email
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:
Add the setting binding
builder.Services.AddOptions<SmtpSettings>() .BindConfiguration("MailSettings") .ValidateDataAnnotations() .ValidateOnStart(); builder.Services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<SmtpSettings>>().Value);
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" }
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>());
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 | 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
- MailKitLite (>= 4.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.