In the theme_mimemail_message function please add $mailkey to the body tag as a css class. This will allow you to change styling for different emails only through mail.css (or the main css file of theme) without overriding the theme_mimemail_message function. The class name should probably be prefixed with something like "mailkey-".

The mailkey would have to be sanitized so it is a safe css class name.

If you can figure the name of the module that called the mimemail function then that can also be added as a class (with a prefix like "module-").

A similar option would be to first try to load 'mail-'. $mailkey .'.css' and if that fails then next try 'mail.css'. Of course, only if mailkey is not NULL. If the module name is available, then here too you could do a two step trial, by having the module name part of the css file name.

For example, if simplenews is sending a mimemail with a mailkey set to "weekly" then the following css files are attempted:

  1. mail-simplenews-weekly.css
  2. mail-simplenews.css
  3. mail.css

And the body tag for this example would look like:
<body id="mimemail" class="module-simplenews mailkey-weekly">

Comments

sgabe’s picture

I have implemented this feature in #743150: Mime Mail 6.x-1.0-beta1?, I would appreciate it if you could test it and report back.

sgabe’s picture

#768216: How to theme different mails marked as a duplicate.

@preper:
@RodrigoBalest:

In the actual state of things this feature depends on several issues that are need to get in before it can be implemented:

Here is the point, there is an id element in the $message array generated by drupal_mail().

...
// Bundle up the variables into a structured array for altering.
$message = array(
  'id'       => $module .'_'. $key,
  'to'       => $to,
  'from'     => isset($from) ? $from : $default_from,
  'language' => $language,
  'params'   => $params,
  'subject'  => '',
  'body'     => array()
);
...

The #567594: $mailkey is not properly set in drupal_mail_wrapper() issue aims to set the $mailkey with the value of the $message['id']. Then we shall use that as another argument, and also the mimemail_message__ pattern in our hook_theme() implementation, what will allow us to use custom CSS and template files like mail-[mailkey].css and mimemail-message--[mailkey].tpl.php.

Another issue that contributed modules e.g Simplenews, should use a proper $mailkey when calling mimemail(), otherwise we won't be able to use this feature. Currently Simplenews (and other contributed modules) doesn't do that. Core modules like Actions and Contact uses mailkeys like system_action_send_email and contact_user_mail. In these cases the files would be mail-contact-user-mail.css and mimemail-message--contact-user-mail.tpl.php. This goes for #501722: HTML mail actions for Rules which doesn't call mimemail() with proper mailkey either. However I'm planning to update that issue with this soon.

In a nutshell, we have a lot to do before we could implement this in a general way. The good news as I posted before, I have implemented this functionality in #743150: Mime Mail 6.x-1.0-beta1?, so you can take a look at that if you would like to try.

sgabe’s picture

Title: add mailkey to body tag as css class » Add $mailkey to body tag as CSS class
Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new714 bytes

The $mailkey variable is already passed to the template, but it doesn't use it.

sgabe’s picture

StatusFileSize
new1.41 KB

Process $mailkey to be a proper CSS class.

sgabe’s picture

StatusFileSize
new1.27 KB

Move the whole thing to template_preprocess_mimemail_message().

sgabe’s picture

Status: Needs review » Fixed

Committed to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

-Mania-’s picture

Should this be working for 6.x? I can't seem to get the mailkey value printed. Every time I send a Simplenews email the body class prints as class="mail-".