Mandrill.net 7.1.1

.NET Standard 2.0 .NET Framework 4.6.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, C# scripting and .NET Interactive. 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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
8.2.0 64,487 4/20/2022
8.1.0 79,526 12/11/2021
8.0.0 1,120 12/10/2021
8.0.0-prerelease4 114 12/10/2021
7.3.2 750,361 8/11/2020
7.3.1 97,395 5/12/2020
7.3.0 1,068 5/10/2020
7.2.0 157,801 3/24/2020
7.1.2 18,587 2/17/2020
7.1.1 213,923 11/30/2019
7.1.0 186,713 4/30/2019
7.0.0 145,523 3/17/2019
6.0.0 37,322 12/29/2018
5.0.0 185,169 6/18/2018
4.2.0 12,618 5/31/2018
4.1.0 362,317 4/9/2017
4.0.0 3,619 3/12/2017
3.3.0 32,750 12/24/2016
3.2.1 11,636 6/28/2016
3.0.0 13,244 5/3/2016
2.2.30 1,628 5/1/2016
2.2.12 7,716 2/18/2016
2.2.0 1,071 2/7/2016
2.1.2 2,051 1/14/2016
2.0.22 2,301 1/3/2016
1.0.2 12,585 8/8/2015
0.9.1 1,111 7/31/2015
0.9.0 1,540 6/20/2015
0.8.0 1,119 5/26/2015
0.7.0 1,909 3/28/2015
0.6.1 1,694 2/19/2015
0.6.0 1,313 2/18/2015
0.5.0 1,245 1/24/2015
0.4.0 1,302 1/15/2015
0.3.0 1,631 1/12/2015
0.2.0 994 1/12/2015