Mandrill

Master Branch Build Status

This is a ColdBox Module to use with the Mandrill API. See the Mandrill API Documentation for more information about the service.

Requirements

  • Lucee 5.2+
  • ColdBox 4.3+
  • Java 8+

Installation

Install using CommandBox: box install mandrill

Within config/Coldbox.cfc add a module settings element named mandrill and define your Mandrill API key in apiKey. Optionally, the default endpoint base URL (https://mandrillapp.com/api/1.0/) may be overridden using endpointBaseUrl:

moduleSettings = {
    "mandrill" = {
        "apiKey" = "YOUR_API_KEY"
    }
};

Usage

The Mandrill client will be instantiated and configured on ColdBox application startup. Inject it where needed, or request it by name. Here's how one might send a message from a ColdBox Handler:

var message = {
    "html": "<h1>Way To Go Donny!</h1><p>If you will it, Dude, it is no dream.</p>",
    "subject": "Over The Line",
    "from_email": "[email protected]",
    "from_name": "Walter Sobchak",
    "to": [
        {
            "email": "[email protected]",
            "name": "Theodore Donald 'Donny' Kerabatsos"
        },
        {
            "email": "[email protected]",
            "name": "The Dude"
        }
    ]
};
getInstance("[email protected]").messages.send(message=message);

It's important to note that the sender address for messages sent through Mandrill must match a verified domain. See the knowledge base article on this topic for more information.

Support

This project is an attempt to mimic the official Mandrill libraries for Python and Node.js. All of the features of the Mandrill API aren't implemented yet. Here's a summary of the calls supported in this version:

/users/info Mandrill.users.info()

/messages/send Mandrill.messages.send(required struct message, boolean async, string ip_pool, string send_at)

/messages/send-template Mandrill.messages.send_template(required string template_name, required array template_content, required struct message, boolean async, string ip_pool, string send_at)

/rejects/list Mandrill.rejects.list(string email, boolean include_expired, string subaccount)

/rejects/add Mandrill.rejects.add(required string email, string comment, string subaccount)

/rejects/delete Mandrill.rejects.delete(required string email, string subaccount)

/whitelists/list Mandrill.whitelists.list(string email)

/whitelists/add Mandrill.whitelists.add(required string email, string comment)

/whitelists/delete Mandrill.whitelists.delete(required string email)

Tests

The package is configured such that tests can be executed within CommandCox using testbox run. Note that environment variables SERVER_HOST and SERVER_PORT can be set to configure the CFML engine used for testing.

By default, the REST calls to Mandrill are mocked. To run the tests against the live Mandrill service, define a valid Mandrill API key as an environment variable (MANDRILL_API_KEY) or a Java system property (mandrill.api.key). Also ensure that authDomain in the test spec configuration is verified and matches the API key.

License

See the LICENSE file for license rights and limitations (MIT).

 

 
$ box install mandrill
No collaborators yet.
  • Sep 28 2017 01:06 AM
  • Oct 11 2018 06:15 PM
  • 241
  • 0
  • 62