Mandrill api wrapper for .net
https://mandrillapp.com/api/docs/
Install-Package Mandrill.net
var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
var message = new MandrillMessage("[email protected]", "[email protected]",
"hello mandrill!", "...how are you?");
var result = await api.Messages.SendAsync(message);
All the api's are available in async or non-async in the .net 4.5 target version of this library. In .NET Core, only async is supported because the underlying api's for web requests in .NET are async only.
var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
var message = new MandrillMessage("[email protected]", "[email protected]",
"hello mandrill!", "...how are you?");
var result = api.Messages.Send(message);
var api = new MandrillApi("YOUR_API_KEY_GOES_HERE");
var message = new MandrillMessage();
message.FromEmail = "[email protected]";
message.AddTo("[email protected]");
message.ReplyTo = "[email protected]";
//supports merge var content as string
message.AddGlobalMergeVars("invoice_date", DateTime.Now.ToShortDateString());
//or as objects (handlebar templates only)
message.AddRcptMergeVars("[email protected]", "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");
[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());
}
- NServiceBus.Mandrill - Integrates NServiceBus messaging framework and mandrill, for more reliable mail processing
See this issue to track progress of api implementation