Carubbi.Mailer.Exchange
2.0.0
dotnet add package Carubbi.Mailer.Exchange --version 2.0.0
NuGet\Install-Package Carubbi.Mailer.Exchange -Version 2.0.0
<PackageReference Include="Carubbi.Mailer.Exchange" Version="2.0.0" />
<PackageVersion Include="Carubbi.Mailer.Exchange" Version="2.0.0" />
<PackageReference Include="Carubbi.Mailer.Exchange" />
paket add Carubbi.Mailer.Exchange --version 2.0.0
#r "nuget: Carubbi.Mailer.Exchange, 2.0.0"
#:package Carubbi.Mailer.Exchange@2.0.0
#addin nuget:?package=Carubbi.Mailer.Exchange&version=2.0.0
#tool nuget:?package=Carubbi.Mailer.Exchange&version=2.0.0
Carubbi.Mailer
A simple library to handle email sending and receiving tasks through pluggable providers with a single abstraction for each direction.
Features
- Send email through SMTP (
Carubbi.Mailer) or Exchange Web Services (Carubbi.Mailer.Exchange). - Receive email from POP3 mailboxes built on MailKit (
Carubbi.Mailer), or through Exchange Web Services (Carubbi.Mailer.Exchange). - Configuration-driven defaults under the
CarubbiMailersection; every setting can be overridden per instance. - First-class
Microsoft.Extensions.DependencyInjectionsupport: implementations are resolved from the standardImplementationsconfiguration section via Carubbi.ServiceLocator, and can be replaced by plain DI registrations at any time. - Optional mailbox drain semantics with cancellation: providers raise
OnMessageReadbefore removing a message, and settingCancelkeeps it on the server.
The legacy Outlook 2007/2010 interop packages are discontinued in 2.x (kept untouched under
legacy/for reference).
Packages
| Package | Description |
|---|---|
| Carubbi.Mailer.Interfaces | Contracts, the message factory and the DI registration helpers. |
| Carubbi.Mailer | SMTP sender and POP3 receiver (MailKit). |
| Carubbi.Mailer.Exchange | Sender and receiver over Exchange Web Services. |
Requires .NET 10.0 or later.
Installation
dotnet add package Carubbi.Mailer
Usage
Given an appsettings.json:
{
"Implementations": {
"IMailSender": "Carubbi.Mailer.Implementation.SmtpSender, Carubbi.Mailer",
"IMailReceiver": "Carubbi.Mailer.Implementation.PopMailReceiver, Carubbi.Mailer"
},
"CarubbiMailer": {
"Smtp": {
"Host": "smtp.example.com",
"PortNumber": 587,
"UseSsl": true,
"Username": "user@example.com",
"Password": "secret"
},
"Pop": {
"Host": "pop.example.com",
"PortNumber": 995,
"UseSsl": true,
"Username": "user@example.com",
"Password": "secret"
}
}
}
Register and resolve through dependency injection:
using Carubbi.Mailer.DependencyInjection;
using Carubbi.Mailer.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var provider = new ServiceCollection()
.AddCarubbiMailer(configuration)
.BuildServiceProvider();
using var sender = provider.GetRequiredService<IMailSender>();
sender.Send(new System.Net.Mail.MailMessage(
"from@example.com", "to@example.com", "Hello", "<p>Hello</p>") { IsBodyHtml = true });
Swap providers without touching consumers by pointing the Implementations section at another type (for example Carubbi.Mailer.Exchange.ExchangeWebServiceSender, Carubbi.Mailer.Exchange), or simply override the registrations:
services.AddCarubbiMailer(configuration)
.AddSingleton<IMailSender>(sp => new SmtpSender(configuration)
{
Host = "smtp.other.com",
PortNumber = 465,
UseSsl = true,
});
Exchange Web Services
Reference Carubbi.Mailer.Exchange and configure:
{
"Implementations": {
"IMailSender": "Carubbi.Mailer.Exchange.ExchangeWebServiceSender, Carubbi.Mailer.Exchange",
"IMailReceiver": "Carubbi.Mailer.Exchange.ExchangeWebServiceReceiver, Carubbi.Mailer.Exchange"
},
"CarubbiMailer": {
"Exchange": {
"Url": "https://mail.example.com/EWS/Exchange.asmx",
"Version": "Exchange2013",
"MailboxName": "shared-mailbox@example.com",
"RetrieveLimit": 10,
"WebProxy": ""
}
}
}
Brazilian HTML messages
using System.Net.Mail;
using Carubbi.Mailer.Interfaces;
using MailMessage message = MailMessageFactory.CreateBrazilianHtmlMessage("Subject", "<p>Acentuação</p>");
// BodyEncoding/SubjectEncoding are ISO-8859-1 and IsBodyHtml is true.
Building and testing locally
Prerequisites:
- .NET SDK 10.0 or later
- Docker (only for the integration test suite)
dotnet build -c Release
dotnet test --solution Carubbi.Mailer.sln
The unit tests run entirely in memory. The integration tests start a GreenMail container providing real SMTP and POP3 servers; when Docker is unavailable those tests are skipped automatically.
The Outlook interop sources kept under legacy/ target the old .NET Framework tooling
and are not part of the solution.
Releases
Releases are published to nuget.org automatically
by the publish workflow whenever a tag matching v* is pushed:
git tag v2.0.0
git push origin v2.0.0
License
Distributed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Carubbi.Mailer.Interfaces (>= 2.0.0)
- Exchange.WebServices.NETCore (>= 3.3.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.