This is a ColdBox Module to use with the Mandrill API. See the Mandrill API Documentation for more information about the service.
- Lucee 5.2+
- ColdBox 4.3+
- Java 8+
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"
}
};
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": "walter@domain.tld",
"from_name": "Walter Sobchak",
"to": [
{
"email": "donny@domain.tld",
"name": "Theodore Donald 'Donny' Kerabatsos"
},
{
"email": "the_dude@domain.tld",
"name": "The Dude"
},
{
"email": "jeffrey.lebowski@domain.tld",
"name": "The Other Jeffrey Lebowski, The Millionaire",
"type": "cc"
}
]
};
getInstance("mandrillClient@mandrill").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.
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)
The package is configured such that tests can be executed within CommandCox using testbox run
after the embedded server is started with server start
.
By default, the REST calls to Mandrill are mocked. To run the tests against the live Mandrill service, define an API key and authorized domain. If you have the dotEnv CommandBox system module installed, this is pretty easy. See the .env.example
file in the project root. It defines the two configuration options:
mandrill.api.key=secret
mandrill.auth.domain=authorized.tld
Copy the example as .env
and plug in your values.
Another option is to configure environment variables in the shell before starting CommandBox. For example:
export MANDRILL_API_KEY="secret"
export MANDRILL_AUTH_DOMAIN="authorized.tld"
See the LICENSE file for license rights and limitations (MIT).