PHPackages                             bertoost/craft-mandrill-service-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. bertoost/craft-mandrill-service-plugin

ActiveCraft-plugin[Mail &amp; Notifications](/categories/mail)

bertoost/craft-mandrill-service-plugin
======================================

Mandrill service plugin for Craft CMS (v2)

v1.1.3(7y ago)0116PHP

Since Jan 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bertoost/Craft-CMS-Mandrill-Service)[ Packagist](https://packagist.org/packages/bertoost/craft-mandrill-service-plugin)[ RSS](/packages/bertoost-craft-mandrill-service-plugin/feed)WikiDiscussions develop Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

Mandrill service plugin for Craft CMS (v2)
==========================================

[](#mandrill-service-plugin-for-craft-cms-v2)

This plugin provides the ability to send emails via Mandrill API. It also can control all of the emails send by Craft's EmailService being captured for sending to Mandrill. Read below for more information.

- [Installation](#installation)
    - [Composer vendor files](#composer-vendor-files)
    - [Enable the plugin in Craft](#enable-the-plugin-in-craft)
    - [Configuration settings](#configuration-settings)
        - [API Key](#api-key)
        - [Enable as a service](#enable-as-a-service)
        - [From settings](#from-settings)
        - [Craft's general config to override](#crafts-general-config-to-override)
- [Take over control of all outgoing emails](#take-over-control-of-all-outgoing-emails)
    - [Manually use the service](#manually-use-the-service)
- [Events](#events)
    - [email.onBeforeSendEmail](#emailonbeforesendemail)
    - [email.onSendEmail](#emailonsendemail)
    - [email.onSendEmailError](#emailonsendemailerror)
- [Examples](#examples)
    - [Add-in tags](#add-in-tags)
    - [Using attachments](#using-attachments)
    - [Set a schedule date/time](#set-a-schedule-datetime)
- [Outbound view](#outbound-view)

Installation
------------

[](#installation)

From the root of your Craft installation, just run composer to install this plugin;

```
composer require bertoost/craft-mandrill-service-plugin

```

This will install the plugin inside your `craft/plugins/` folder automatically.

### Composer vendor files

[](#composer-vendor-files)

It also brings some other vendor files inside the `vendor/` directory in your project root. This can be ignored by your VCS or included when you aren't able to run `composer install` at your hosting-server.

Maybe your installation is configured to use another path structure. If the plugin can't find the Composer `vendor/` folder, it will notify you in the admin panel. To solve it, you can tell us where to find the `vendor/` folder. Just add this line to your websites' index.php file, just below the `$craftPath` definition.

```
define('COMPOSER_VENDOR_PATH', realpath('../vendor/'));
```

### Enable the plugin in Craft

[](#enable-the-plugin-in-craft)

Navigate to Craft's settings &gt; Plugins &gt; Install `Mandrill Service` plugin.

### Configuration settings

[](#configuration-settings)

[![Settings](resources/docs/screenshots/settings-page.png "Settings")](resources/docs/screenshots/settings-page.png)

#### API Key

[](#api-key)

After installation you have to configure the plugin to work at all. Navigate to the plugin settings page and enter the API key you want to use.

**Remember:** Mandrill provides the ability to have a test-API-key. You can test it as many times you want without having a paid account already. Login to Mandrill and activate a "Test" API key.

#### Enable as a service

[](#enable-as-a-service)

There are two ways of using this plugin. You can use the Mandrill service or let it take over control of sending any email, sent by Craft's EmailService. This is a setting in the plugin;

#### From settings

[](#from-settings)

The from email and name settings are meant to configure the sender name for your site/application. This can be overwritten when using manual service, but this config settings are used by default.

#### Craft's general config to override

[](#crafts-general-config-to-override)

You can pass the following settings to the `general.php` configuration file of Craft, to override the settings in the settings page from the plugin.

```
return [
    // ...
    'mandrillEnabled'   => false,
    'mandrillApiKey'    => 'TheKeyFromMandrill',
    'mandrillFromEmail' => 'you@address.mail',
    'mandrillFromName'  => 'Your Sender Name',
];
```

Take over control of all outgoing emails
----------------------------------------

[](#take-over-control-of-all-outgoing-emails)

**Downside (read carefully):**

The plugin hooks on the `email.onBeforeSendEmail` event and disables any further process of Craft's EmailService (by setting `$event->performAction = false;`). It also will re-fire that event, to be sure all data from any plugin is captured before sending it.

So, why is this a bad thing? Because it can happen (actually: it will!) that your plugin already did it's work before this event reaches the Mandrill-take-over part. But when not, we fire the event again to be sure it will. This will cause a second roundtrip of the `email.onBeforeSendEmail` event. Depending on what happens on this event, it can slow down the process!

If you're building heavy stuff on this event, it can be good to check if you did your thing already. Like this;

```
craft()->on('email.onBeforeSendEmail', function (Event $event) {

    // check if we've been here before
    if (!isset($event->params['myplugin_beenHere'])) {

        // do your stuff here

        $event->params['myplugin_beenHere'] = true;
    }
});
```

It will not stop coming here twice, but the hard part (or load/performance taking part) of your code will be skipped.

### Manually use the service

[](#manually-use-the-service)

It's also possible to use the Mandrill service manually.

```
$variables = [
    // any template variables
];

$htmlBody = /* Some HTML content, parsed by Twig?! */;
$plainTextBody = /* Some plain text content, parsed by Twig?! */;

craft()->mandrill
    ->addTo('email@ddre.ss', 'Sender Name')
    ->setContent($htmlBody, $plainTextBody, $variables)
    ->send();
```

Using Craft's messages system

```
// get any UserModel anyhow, example:
$user = craft()->users->getUserByEmail('me@example.com');

$variables = [
    // any template variables
];

craft()->mandrill
    ->setUser($user)
    ->setByEmailKey('the_message_key', $variables)
    ->send();
```

Events
------

[](#events)

The Craft email events are still being used. They contain the same params as the event is getting from Craft's default EmailService.

```
[
    'user'       => /* an UserModel */,
    'emailModel' => /* an EmailModel */,
    'variables'  => /* an array of variables */,

    // and on error:
    'error'      => /* error message */,
]
```

Additional params are added by the Mandrill service

### email.onBeforeSendEmail

[](#emailonbeforesendemail)

```
[
    // ...
    '_mandrill'    => true,
    'emailMessage' => /* a Mandrill_MessageModel */,
]
```

### email.onSendEmail

[](#emailonsendemail)

```
[
    // ...
    '_mandrill'    => true,
    'emailMessage' => /* a Mandrill_MessageModel */,
    'result'       => /* array of the Mandrill API result */,
]
```

### email.onSendEmailError

[](#emailonsendemailerror)

```
[
    // ...
    '_mandrill'    => true,
    'emailMessage' => /* a Mandrill_MessageModel */,
]
```

Examples
--------

[](#examples)

Find some example usages below

### Add-in tags

[](#add-in-tags)

Your plugin can add tags to email messages easily since the `emailMessage` is passed by the events given by the Mandrill plugin. Example;

**When using service manually;**

```
// attachment as content
craft()->mandrill
    // ...
    ->addAttachment('my.pdf', $fileContents, 'application/pdf');

// or as a file path
craft()->mandrill
    // ...
    ->addAttachmentFile('path/to/my.pdf', 'alternate-name.pdf', 'application/pdf')
```

**When the "Mandrill as service" is on;**

```
craft()->on('email.onBeforeSendEmail', function (Event $event) {

    // to be sure it happens when Mandrill is here
    if (isset($event->params['_mandrill'])) {

        // single one
        $event->params['emailMessage']
            ->addTag('Tag name one')
            ->addTag('Tag name two');

        // or as array
        $event->params['emailMessage']
            ->addTag(['Tag name one', 'Tag name two']);

        // based on messages-system email-key
        switch ($event->params['variables']['emailKey']) {
            case 'forgot_password':
                $event->params['emailMessage']
                    ->addTag('Forgot password');
                break;
        }
    }
});
```

### Using attachments

[](#using-attachments)

**When using service manually;**

```
// attachment as content
craft()->mandrill
    // ...
    ->addAttachment('my.pdf', $fileContents, 'application/pdf');

// or as a file path
craft()->mandrill
    // ...
    ->addAttachmentFile('path/to/my.pdf', 'alternate-name.pdf', 'application/pdf')
```

**When the "Mandrill as service" is on;**

```
craft()->on('email.onBeforeSendEmail', function (Event $event) {

    // to be sure it happens when Mandrill is here
    if (isset($event->params['_mandrill'])) {

        $event->params['emailMessage']
            ->addAttachment('my.pdf', $fileContents, 'application/pdf');
    }
});
```

### Set a schedule date/time

[](#set-a-schedule-datetime)

**When using service manually;**

```
$dateTime = new DateTime();
$dateTime->modify('+2 hours');

craft()->mandrill
    // ...
    ->setSentAt($dateTime);
```

**When the "Mandrill as service" is on;**

```
craft()->on('email.onBeforeSendEmail', function (Event $event) {

    // to be sure it happens when Mandrill is here
    if (isset($event->params['_mandrill'])) {

        $dateTime = new DateTime();
        $dateTime->modify('+2 hours');

        $event->params['mandrillSentAt'] = $dateTime;
    }
});
```

Outbound view
-------------

[](#outbound-view)

The plugin comes with a very cool overview where you can see the outbound of Mandrill. It shows you if messages are sent correctly and also gives you an inside when it failes or bounces. All of this can be found in Mandrill too of course.

[![Outbound page](resources/docs/screenshots/outbound-page-example.png "Outbound page")](resources/docs/screenshots/outbound-page-example.png)

To enable this feature, you have to add a sync script to your cronjob system. This is the call you have to make (for example 1 to 4 times a day).

```
php craft/app/etc/console/yiic mandrill syncOutbound

```

You can also use this command to sync it manually.

**Note:** This command scans Mandrill till 4 days in the past. Since bounces are being tried a couple of times.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~42 days

Total

10

Last Release

2900d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/398492?v=4)[Bert Oost](/maintainers/bertoost)[@bertoost](https://github.com/bertoost)

---

Top Contributors

[![seanjermey](https://avatars.githubusercontent.com/u/15254335?v=4)](https://github.com/seanjermey "seanjermey (1 commits)")

---

Tags

craftcmscraftcms-pluginmandrill

### Embed Badge

![Health badge](/badges/bertoost-craft-mandrill-service-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/bertoost-craft-mandrill-service-plugin/health.svg)](https://phpackages.com/packages/bertoost-craft-mandrill-service-plugin)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[etailors/mautic-amazon-ses

Amazon SES Mailer Plugin for Mautic

563.4k](/packages/etailors-mautic-amazon-ses)[pressbooks/pressbooks-book

This theme is named after Canadian media theorist Marshall McLuhan, who coined the phrase “the medium is the message.” It is designed for academic writing and is also suitable for fiction. Headings are set in Cormorant Garamond, and body type is set in Lora.

206.7k](/packages/pressbooks-pressbooks-book)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
