📅 Fireside Chat: Future of Analytics on the Modern Data Stack with Hex, Transform, and RudderStack

Register Now →
By Rudderstack Team

How to Load data from Mandrill to MS SQL Server

This post helps you with loading your data from Mandrill to MS SQL Server. If you are looking to get analytics-ready data without the manual hassle, you can integrate Mandrill to MS SQL Server with RudderStack, so you can focus on what matters, getting value out of your data.

How to Extract my Mandrill’s data?

There are two main methods to get our Mandrill’s data, the first one is to pull data out from it and the second one is to ask Mandrill to push data to us whenever something of importance happens. We will see the difference between these two solutions and how we can have data access from both.

In order to pull data out of Mandrill, we need to access its HTTP API. As a Web API following the RESTful architecture principles, it can be accessed through HTTP. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework.

A few suggestions:

  • Apache HttpClient for Java
  • Spray-client for Scala
  • Hyper for Rust
  • Ruby rest-client
  • Python http-client

Mandrill maintains a number of officially supported clients or SDKs that you can use with your favorite language to access it without having to mess with the raw underlying HTTP calls.
These are the following:

There are also a number of unofficial clients that you can use if you prefer. The complete list can be found here.

In this post, we will consider the more generic case of accessing the HTTP endpoints directly for our examples, but of course, you are free to use the client of your choice for your project.

Mandrill API Authentication

In order to use the Mandrill API, you first have to generate an API key through your MandrillApp account. When you have created the key, you can use it to access the API.

You can actually have multiple keys per account, something that adds versatility to the platform. In most cases, with the Mandrill API, you make a POST call to access an endpoint with a JSON body containing the access key.

Mandrill rate limiting

API rate limiting with Mandrill is a bit of a more complicated matter than in most cases of APIs out there. The reason is that Mandrill is mainly an SMTP as a service platform, in most cases, when we make a call to its API, we do it in order to send an e-mail to someone, so rate-limiting in the typical sense that we find it in web APIs does not apply in Mandrill.

What is actually happening is that every Mandrill account has a reputation and an hourly quota. The main reason that rate limiting is a bit more complicated in Mandrill is that they need to take special care of pointing out and handling potential spammers.

So the hourly quota is affected by your reputation, if for example, you have a poor reputation then Mandrill will reduce the number of e-mails and consequently the API calls that you can do on a per hour basis, on the contrary, if you have an excellent reputation you will be able to make more calls. Free accounts can send up to 25 emails per hour.

If you want to find your hourly quota and reputation, you will have to check your Dashboard in MandrillApp.

Endpoints and available resources

Mandrill exposes the following endpoints:

  • Users: Information about your account. For example, here, you can validate that your API key is valid.
  • This endpoint is used to send messages through the Mandrill API.
  • Information and operation about user-defined tags.
  • Rejects. Manage your email rejection list.
  • Whitelists. Manage your rejection whitelists.
  • Senders. Manage senders associated with your Mandrill account.
  • Get information about the URLs that are included in your e-mails.
  • Manage e-mail templates.
  • Webhooks. Manage webhooks for your account.
  • Subaccounts. Manage subaccounts.
  • Information about domains that have been configured for inbound delivery.
  • Run export jobs to retrieve data out of your Mandrill account.
  • IPs. Information and operations about your dedicated IPs.
  • Information and operations about your custom metadata fields indexed for the account.

The above endpoints define the complete set of operations that we perform with Mandrill. In our case, we care mainly about what data we can export so we will work with the export endpoint. Export jobs can be executed for the following data:

  • Export your rejection blacklist.
  • Export your rejection whitelist.
  • Export your activity history.

We assume that you would like to export your activity data. In order to do that, you must perform a POST request to the following endpoint:

/exports/activity.json

Keep in mind that the base URL might change depending on the warehouse where your application is hosted. For this reason, we will mention only the endpoints, and you will have to prepend the base URL for your case.

The body that we should post to the above end-point should look like this.

{
"key": "example key",
"notify_email": "[email protected]",
"date_from": "2013-01-01 12:53:01",
"date_to": "2013-01-06 13:42:18",
"tags": [
"example-tag"
],
"senders": [
],
"states": [
"sent"
],