Module to Import MailChimp Newsletters into your Drupal Site
A few (well, three - I'm saying three counts as a few) people over at g.d.o asked to try out a module I wrote for a client of ours a few weeks ago. So I'm putting up the first beta of it here.
Behold, the first generation of the MailChimp Import module (Drupal 6 only). This module does no more, and no less, than import your MailChimp campaigns into your Drupal site as nodes. Why would you want to do that, when MailChimp already provides online versions of your newsletters? Because your client asks for it, that's why. Perhaps they want to be able to file their sent newsletters alongside their other content, in the system of taxonomy that suits their particular mental aesthetic. Perhaps they want website visitors to be able to find articles in their old newsletters from the search box in the header of their Drupal site. Perhaps they don't trust that cheerful monkey.
For those who need a little context, here's a quick primer on MailChimp: It's a very nice third-party newsletter and mailing list management system. Very friendly, and even the free account is quite robust. In the parlance of MailChimp, newsletters are "campaigns", which is why I'm referring to them as such, even though you and I both know perfectly well that newsletters are newsletters.
How you use this module:
- Install in the usual way.
- Configure, at admin/settings/mailchimp/import. (Here, have a screenshot.) Currently the only settings are which of your MailChimp mailing lists you want to import the campaigns from, and what node type and input format you want to use for the imported nodes.
- Import campaigns!

How it works:
Dependencies: It depends on MailChimp module, because MailChimp module has two things I wanted to use: a) a copy of the MailChimp API; b) a configuration page where you enter your MailChimp API key.
API: It uses the MailChimp API to extract the lists and sent campaigns from your MailChimp account.
Schema: It creates a table with two columns, to store drupal node ID's against MailChimp campaign ID's.
Cron: It automatically checks your MailChimp account for new campaigns to import (and imports them if it finds any), on each cron run. Plus there's an "Import campaigns" button there on the settings page in case you don't wanna wait.
Text processing: It provides options for stripping out potentially layout-destroying tags such as <head>, <style> and <script>, along with all the code inside them, from the campaign content.
CSS help: It includes optional CSS for hiding elements of the email, such as the header and footer. The tricky part: you'll have to edit your campaign template in MailChimp and add the CSS class .mailchimp-hide to the parts you'll want to be visible in your emails, but not visible in the imported version on your Drupal site. The README contains hopefully useful instructions on how to set that up.
How it doesn't yet work, but maybe after my nap:
The module was dashed off pretty quickly, and needs various kinds of love before it'll be ready to contribute.
I want to add settings for the following:
- node title, maybe with some tokens (currently sets the node title to the email subject line)
- taxo terms to apply
- CCK field mapping
- whether or not to import on cron runs, perhaps how often to import
- the option to do all this importing through the Feeds API, for the joy of consistent content handling
Moreover, some people who see the name "MailChimp Import" will likely be hoping for a module that will import MailChimp subscribers as Drupal user accounts. Eh, you want that, go help develop EMF module.
Now soliciting feedback. Everyone, especially people who commented on my g.d.o post, please try out the module and complain mightily! Code quality, features, security, EMF compatibility - get crazy!
UPDATE: New version, now compatible with Mailchimp module 6.20. Implemented zzolo's recommended code cleanups from here.
| Attachment | Size |
|---|---|
| mailchimp_import.tar_.gz | 5.79 KB |





















Comments
Have you considered writing a Feeds plugin?
Nice work!
Have you considered writing a Feeds plugin? If Mailchimp import would be a Feeds parser and you would get the following items for free:
* Storage for Newsletter ID per imported node
* CCK field mapping
* Taxonomy mapping
* Potential other benefits by being compatible with Feeds plugins.
Hunt me down on IRC #drupal or send me an email through my d.o. account, I'd be happy to give you a more concrete notion of how you could use Feeds and why you would want to do that.
Hmmmmmm.... I like
Hey Alex! I must admit I hadn't considered doing the importer as a Feeds parser, but I like it a lot. It gets me the CCK and taxonomy mapping I wanted, plus gets rid of extra DB table, probably has a host of boons in terms of interoperability with other stuff, yakety yak. I'm going to look at that first next time I sit down to do a round of AB-sponsored contrib.
You should indicate that this
You should indicate that this is a D6 only module. The MailChimp module still has a supported D5 branch, and I got all excited until I got the dreaded "Depends on: Array (missing)" message from my D5 module list.
I will definitely check this out once we get the D6 migration completed.
Right you are.
Right you are.