I am using Drupal 6 with the Open Atrium distribution, as for now I am able to send email notifications every time I post or edit a news. However I'd like to create more message templates, specifically I'd like to use a different template based on the news tags. For instance if I publish a news with "gallery" tag I want to use a dedicated template and so on. Any idea on how I can accomplish that? Many thanks.

2 Answers 2


Previewable email templates is a good module and supports Rules and Tokens.

The Previewable Email Template (PET) module lets you create email templates, with token substitution, which can be previewed by the user before sending. The emails can be sent to one or many email addresses in a flexible way, and the recipients may or may not be Drupal account holders (users).

  • This module does not do what the OP wants. It does not allow emails templates to be created based on taxonomy terms. It allows you to use tokens. The op wants automatic templates for each one of the taxonomy terms associated with the content type. The only way to accomplish this at this time is by using a custom module to select templates based on these terms. To create the templates, you may be able to use this however the answer I provided is much more complete and flexible method for accomplishing the goal. This answer doesn't provide any solution, just a reference to a module. May 18, 2013 at 3:46
  • 2
    @BrandonBearden, actually, I think PET would work for this -- the op wants to create multiple templates and use them for different taxonomy terms; he doesn't state that he wants the templates created for him. PET doesn't send the emails automatically, which means you'd have to use Rules (or cronned functions) to send them. So you'd use PET to manage your multiple templates and allow your rules to fill-and-send the appropriate template based on the taxonomy of the newly created content. I'm not certain that PET is the best option, but it serves for template management & using node tokens. Dec 2, 2013 at 14:37

I don't know if you can do this strictly with rules and mimemail. I would supsect that the tie to taxonomy, rules and mimemail doesn't exist through the user interface of these modules. However, I know you could accomplish this within a custom module, a rules hook and mimemail. A simple example of how to use mimemail in a custom module is:

// email body
$email = "<h1>blah header</h1> <br> <p style="some inline styles">blah blah blah</p>";

$message = array(
  'to' => "[email protected]",
  'subject' => "yes, a subject",
  'body' => $email,  

// Optionally add an attachement, this is an example from a form submit handler
$message['params']['attachments'][] = array(
  'filepath' => $form_state['values']['file'],

$MimeMailSystem = drupal_mail_system('mimemail', 'your_mime_template');
$message = $MimeMailSystem->format($message);

  drupal_set_message('booo, not sent.', 'error');  

This example is for Drupal 7, I don't have any D6 installations to check but it should not be wildly different and I think is the same.

For completeness, if someone does ever want to add an attachment, here is the validate submit handler:

function _module_formname_validate($form, &$form_state)
    $file = file_save_upload('formFileField', array('file_validate_extensions' => array()));
       if($file = file_move($file, 'public://')){
          $ext = strtolower(pathinfo($file->uri, PATHINFO_EXTENSION));
          //Acceptable extensions
          if ($ext === 'pdf' || $ext === 'doc' || $ext === 'docx' || $ext === 'txt') {
             $form_state['values']['file'] = $file->uri;
          else {
             form_set_error("formField","Your file must be in a PDF, doc, docx or txt format.");
    else {
       // Do something about the form not having an attachement, or don't.
       //form_set_error("formField","error, no attachement.");

Update: For clarity, this is a completely viable solution. mimemail allows you to create custom templates based on modules. So, you would have to write a module that would create a template based on the taxonomy you desire. Otherwise, there is no way I can find to create different email templates based on taxonomy terms. So, this solution would be a great fit to solve this rather complex problem. In addition, it is very easy to create the templates themselves through the UI admin menu that mimemail has created. Hope this is helpful to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.