I created my own template, added to my style.css needed rules, but e-mail comes unstyled - without any css rules (but I can see that it uses proper template).
I tried to insert

with rules in template, but it renders as plain text in e-mail. I'm also using Mail MIME (6.x-2.17) and Emogrifier (6.x-1.18) but they doesn`t help at all. I was doing every thing as described here http://drupal.org/node/1124376 and here http://drupal.org/node/1124376 What I can do wrong? And how I can make e-mail to come styled?

Comments

roball’s picture

Title: Can`t get styles to work. » How to add CSS into the HTML mail
Status: Active » Needs review

I have solved this by editing the htmlmail.tpl.php template residing in your Email theme directory to contain the following:

<?php

/**
 * @file
 * Fallback-Template for HTML Mail messages.
 */

  $css_file = realpath(path_to_theme()) . '/mail.css';
  if (!empty($css_file) && file_exists($css_file)) {
    $css = file_get_contents($css_file);
  }
?>

<html>
<head>
<style type="text/css">
<!--
<?php print $css ?>
-->
</style>
</head>
<body>

<div class="htmlmail-body">
<?php echo $body; ?>
</div>

<?php if ($debug): ?>
(...)
<?php endif; ?>

</body>
</html>

This will insert the contents of a mail.css CSS definitions file residing in your current theme directory. Thus the same CSS file used by the Mime Mail module will also be used by the HTML Mail module.

Make sure to
ln -s htmlmail.tpl.php htmlmail-htmlmail.tpl.php
in the current theme directory, so the same template will also be used to send test mails by the HTML Mail module from admin/settings/htmlmail/test.

jacob.embree’s picture

Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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