Skip to content
Go to file

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

Coverage Status Dependabot Status

API Docs

Getting Started



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


You must set the user environment variable MANDRILL_API_KEY in order to run these tests. Go to 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 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("", "",
                "hello mandrill!", " 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 = "";
message.ReplyTo = "";
//supports merge var content as string
message.AddGlobalMergeVars("invoice_date", DateTime.Now.ToShortDateString());
//or as objects (handlebar templates only)
message.AddRcptMergeVars("", "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");

Processing a web hook batch

public IHttpActionResult MyWebApiControllerMethod(FormDataCollection value)
    //optional: validate your webhook signature
    // see
      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();

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

API coverage

See this issue to track progress of api implementation

You can’t perform that action at this time.