Mandrill.net 7.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mandrill.net --version 7.1.1                
NuGet\Install-Package Mandrill.net -Version 7.1.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="Mandrill.net" Version="7.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mandrill.net --version 7.1.1                
#r "nuget: Mandrill.net, 7.1.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 Mandrill.net as a Cake Addin
#addin nuget:?package=Mandrill.net&version=7.1.1

// Install Mandrill.net as a Cake Tool
#tool nuget:?package=Mandrill.net&version=7.1.1                

Mandrill.net

Simple, cross-platform Mandrill api wrapper for .NET Core and .NET 4.6+

Coverage Status <a href="http://www.nuget.org/packages/Mandrill.net/"><img src="https://img.shields.io/nuget/v/Mandrill.net.svg" title="NuGet Status"></a> Dependabot Status

API Docs

https://mandrillapp.com/api/docs/

Getting Started

Install-Package Mandrill.net

Building

dotnet build src/Mandrill.net
# if on mac/linux, you cannot build against the .net461 target:
# dotnet build src/Mandrill.net -f netstandard2.0

Testing

You must set the user environment variable MANDRILL_API_KEY in order to run these tests. Go to https://mandrillapp.com/ to obtain an api key.

In order for the email from address to match your allowed sending domains, you can set MANDRILL_SENDING_DOMAIN to match your account.

# include MANDRILL_API_KEY and MANDRILL_SENDING_DOMAIN in your env. For example:
# MANDRILL_API_KEY=xxxxxxxxx MANDRILL_SENDING_DOMAIN=acme.com dotnet test tests
dotnet test tests

Send a new transactional message through Mandrill

var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
var message = new MandrillMessage("from@example.com", "to@example.com",
                "hello mandrill!", "...how are you?");
var result = await api.Messages.SendAsync(message);

Send a new transactional message through Mandrill using a template

var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
var message = new MandrillMessage();
message.FromEmail = "no-reply@acme.com";
message.AddTo("recipient@example.com");
message.ReplyTo = "customerservice@acme.com";
//supports merge var content as string
message.AddGlobalMergeVars("invoice_date", DateTime.Now.ToShortDateString());
//or as objects (handlebar templates only)
message.AddRcptMergeVars("recipient@example.com", "invoice_details", new[]
{
    new Dictionary<string, object>
    {
        {"sku", "apples"},
        {"qty", 4},
        {"price", "0.40"}
    },
    new Dictionary<string, object>
    {
        {"sku", "oranges"},
        {"qty", 6},
        {"price", "0.30"}

    }
});

var result = await api.Messages.SendTemplateAsync(message, "customer-invoice");

Service Registration

It is recommended that you do not create an instance of the MandrillApi for every request, to effectively pool connections to mandrill, and prevent socket exhaustion in your app. For example, an ASP.NET Core service registration that registers the API Interfaces as singletons:

var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
services.AddSingleton<IMandrillMessagesApi>(api.Messages);

Processing a web hook batch

[HttpPost]
public IHttpActionResult MyWebApiControllerMethod(FormDataCollection value)
{
    //optional: validate your webhook signature
    // see https://mandrill.zendesk.com/hc/en-us/articles/205583257-How-to-Authenticate-Webhook-Requests
    if(!ValidateRequest(value))
    {
      return Forbidden();
    }

    var events = MandrillMessageEvent.ParseMandrillEvents(value.Get("mandrill_events"));
    foreach (var messageEvent in events)
    {
        // do something with the event
    }
    return Ok();
}

private bool ValidateRequest(FormDataCollection value)
{
   IEnumerable<string> headers;
   if (!Request.Headers.TryGetValues("X-Mandrill-Signature", out headers))
   {
     return false;
   }
   var signature = headers.Single();
   var key = "MANDRILL_WEBHOOK_KEY_HERE";

   return WebHookSignatureHelper.VerifyWebHookSignature(signature, key, Request.RequestUri, value.ReadAsNameValueCollection());
}

API coverage

See this issue to track progress of api implementation

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Mandrill.net:

Package Downloads
Mandrill.net.Extensions.DependencyInjection

integrate Mandrill.net with HttpClientFactory and Microsoft.Extensions.DependencyInjection

NServiceBus.Mandrill

NServiceBus feature to send Mandrill API requests over the bus

Webezi.MailKit.Mandrill

Webezi.MailKit.Mandrill is used Mandrillto implements mailkit abstractions.

Altairis.Services.Mailing.Mandrill

E-mail sending services for ASP.NET Core applications using the Mandrill service.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.1 153,781 3/26/2024
9.0.0 27,426 2/29/2024
8.3.0 103,982 11/20/2023
8.2.0 528,246 4/20/2022
8.1.0 250,987 12/11/2021
8.0.0 1,291 12/10/2021
8.0.0-prerelease4 216 12/10/2021
7.3.2 1,881,484 8/11/2020
7.3.1 131,535 5/12/2020
7.3.0 1,256 5/10/2020
7.2.0 171,369 3/24/2020
7.1.2 23,717 2/17/2020
7.1.1 225,402 11/30/2019
7.1.0 274,540 4/30/2019
7.0.0 168,395 3/17/2019
6.0.0 64,769 12/29/2018
5.0.0 203,270 6/18/2018
4.2.0 13,557 5/31/2018
4.1.0 565,002 4/9/2017
4.0.0 4,136 3/12/2017
3.3.0 40,271 12/24/2016
3.2.1 15,451 6/28/2016
3.0.0 14,506 5/3/2016
2.2.30 3,541 5/1/2016
2.2.12 11,444 2/18/2016
2.2.0 1,271 2/7/2016
2.1.2 2,718 1/14/2016
2.0.22 2,855 1/3/2016
1.0.2 15,389 8/8/2015
0.9.1 1,344 7/31/2015
0.9.0 1,818 6/20/2015
0.8.0 1,321 5/26/2015
0.7.0 2,318 3/28/2015
0.6.1 1,911 2/19/2015
0.6.0 1,524 2/18/2015
0.5.0 1,501 1/24/2015
0.4.0 1,639 1/15/2015
0.3.0 1,947 1/12/2015
0.2.0 1,413 1/12/2015