A recipe for building newsletters in Drupal

Update on April 9, 2013 - the description of Drupal 7 version of this module with links to the module files is available here

I'll start right away by saying that sending newsletters with Drupal is excruciatingly painful, and we do not recommend it at all unless you're subscriber-ship is extremely low. Many other software packages and solution providers do it much better than Drupal ever will. So this isn't about sending your newsletter, it's about how to build your newsletter for email and web delivery.

Our method is simple. Similar to modules like Simplenews we will be creating a newsletter content type that will store the contents of the newsletter. The only difference is that Drupal will not be sending the emails. We will be exporting HTML to our newsletter sending application of choice (We use CiviCRM).

The basic structure of the node depends on the structure of your newsletter. We will use our Freeform newsletter as an example. Our newsletter consists of a number of various sections almost all of which are controlled by CCK fields.

Our newsletter content types consist of:

  • Text fields for section headers
  • Textarea for header and footer text
  • node reference fields for content

In order to make finding node references easier for our clients we usually install the Nodereference explorer module which provides a customizable view in a modal popup where the user can select which item they want from a list.

Once our newsletter is populated with our content we now have a published newsletter node. Awesome! Except now we need to export this to email client friendly HTML for our email blast.

This is where our custom module Newsletter Export comes in. This module works as follows, in the newsletter export settings page select the type of node you want the ability to export. Users with appropriate permissions will then see a "Newsletter Export" link in the links area of content of that type. Clicking on the export link will generate an HTML file with the output of just that node.

The output can be customized in two ways. First a new Build mode will be available in the "Display Fields" section called "Newsletter", you can choose to exclude fields, or change display modes and it will be reflected in the output. The other way is to edit the included newsletter-export.tpl.php file that comes with the module. Copy it to your theme directory and modify the output.

The template has three variables which it can access

  1. $raw_markup - The standard drupal output of the node (default behaviour)
  2. $fields - an array of all the fields including body and title of the node
  3. $node - the full node object

Using these variables you can manipulate and create the output however you like. After our designer created and tested the raw HTML version of our newsletter we took that HTML placed it in the template and replaced the static text with variables from our node. Some small bits of PHP for basic logic (if, foreach, etc) was required, but that is generally allowed in templates.

The result is an easy to export HTML email ready version of our newsletter node that can be used in whatever email newsletter application you want.

Our sandbox project for Newsletter Export can be found here: http://drupal.org/sandbox/tkamen/1321154


Or we can use the new D7

Or we can use the new D7 Newsletter modules with all of this baked in http://drupal.org/project/newsletter

The aim of this module is to export to html

The aim of this module is to export to html and add that html to your newsletter program. newsletter for D7 is integrated into your drupal install so users can who are on your site can subscribe etc...I don't see where you can export a newsletter to html.

With the setup shown on this

With the setup shown on this post, all newsletters are sending separately in other email clients instead of performing within drupal?

Drupal should have a first class newsletter system

I don't understand why most don't make it a priority to build a great newsletter system for Drupal -- why would you want to use (mostly) paid third-party systems for your clients' newsletters? Drupal does everything else well, why shouldn't we also build a first class open source newsletter system, when newsletters are such an important part of marketing a website? It seems to go against the grain to me.

Simplenews is a big rough around the edges, it is true... I haven't tried Newsletter yet... but I hope it's coming along. But why would CiviCRM be able to get it right, but not Drupal? All the money people are sending to MailChimp or Constant Contact could have gone towards developing a superb solution right in our own software.

Or am I thinking of this in the wrong way?

newsletter module - export HTML file for 3rd party newsletter

All those comments are great, so I will try to provide some answers.

The reason we've created Newsletter module was because client had an existing CRM system (CiviCRM to be exact) and wanted to re-use the content populated in Drupal for newsletter. Also, they wanted to be assured that the Drupal exported content will have proper formatting so that when used for sending emails, proper template (look and feel) is preserved.

Since then, we've used this Newsletter module for multiple projects, all of them having Drupal as CMS and CiviCRM as CRM.

The reason we use non-Drupal (CiviCRM) solutions for sending/managing newsletters is that CiviCRM provides us with holistic information about contacts - including information when and what newsletter was send to that contact, donations/contributions, phone calls, regular mail, event registration etc. If we would send newsletter through Drupal and record other contact activities in CRM, we would be missing on that global view of interactions with contacts.

If someone is using CRM only for the purpose of sending newsletters, then there may not be a difference to send newsletters through Drupal or use 3rd party software, but if there is a desire to have a global view of all interactions with contacts in one place, using CRM is our preferred choice. In that case, Newsletter module comes in handy to re-use existing Drupal content to populate a newsletter that is send through CRM.


really enjoyed your article.

Suggestions for Drupal 7?

We are using CiviCRM and Drupal 7. Do you have a recommendation that best approach to doing something similar? The modules your reference appear to be for Drupal 6. Thanks!

Drupal 7.x version of the module

The Drupal 7 version of the newsletter export module is here:

The most recent Drupal 6 version is here: https://github.com/freeform/newsletter_export/tree/6.x

We've improved a bit on the functionality and will be writing later some documentation to explain how to modify the display of the newsletter pages.

Drupal 7.x version of the module

The module how-to and files are available here: http://www.freeform.ca/en/blog/updated-recipe-building-newsletters-drupal-7
We are working on publishing it on drupal.org

Tighter integration with CiviCRM?

Just wondering if you were considering making a tighter integration from CiviCRM into the Drupal to pull in the newsletter node's content?

Cutting and pasting from one part of site or from a downloaded file is less than ideal as a user friendly UI.

Upload file, not cut and paste

Sorry, I forgot that one can upload a file as well as use the WYSIWYG CiviMail editor for the content of a mailing. Downloading is thus not that bad, even if it would be nice to integrate it a bit more tightly into the CiviMail interface, eg via a custom token.

Not at the moment

no, we are not planning at the moment a better integration with between Drupal generated HTML export file and CiviCRM newsletter - we are relying on the CiviCRM UI that allows to upload file when creating a new mass-mailing/newsletter. In the near future, we will be focusing on improving sample CSS for the newsletter so that it's compatible with more email clients out of the box.

My own drupal newsletter recipe

I had a similar post on my site about using drupal to pull out newsletters. Here I leave you with my own newsletter flavour, based on several tutorials around: http://www.piofernandes.pt/site/en/programming/drupal-and-newsletter-setup

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Allowed HTML tags: <p> <br> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.