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
                    
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="Carubbi.Mailer.Exchange" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Carubbi.Mailer.Exchange" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Carubbi.Mailer.Exchange" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Carubbi.Mailer.Exchange --version 2.0.0
                    
#r "nuget: Carubbi.Mailer.Exchange, 2.0.0"
                    
#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.
#:package Carubbi.Mailer.Exchange@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Carubbi.Mailer.Exchange&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Carubbi.Mailer.Exchange&version=2.0.0
                    
Install as a Cake Tool

Carubbi.Mailer

NuGet CI License: MIT

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 CarubbiMailer section; every setting can be overridden per instance.
  • First-class Microsoft.Extensions.DependencyInjection support: implementations are resolved from the standard Implementations configuration section via Carubbi.ServiceLocator, and can be replaced by plain DI registrations at any time.
  • Optional mailbox drain semantics with cancellation: providers raise OnMessageRead before removing a message, and setting Cancel keeps 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 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. 
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
2.0.0 71 8/26/2026
1.1.0 1,334 8/20/2018