Sorry if this isn't in the right forum, I'm not sure how to post this to an issue for simplenews and I'm not sure it is simplenews either.

I'm sending out a newsletter using a template I got from MailChimp. At the moment I'm not even sending out any content just the template as it came with lorem ipsum.

When the email is received by gmail or hotmail it has inlined padding 0.3em and 0.5em and width 100% added to tables and td tags automatically. If I add widths to these tags myself inlined or as properties of the html element they are still added and overwrite or seem to be higher priority. I added !important to the inlined styles to enforce them but that still doesn't work. So my final test was overwriting the email being sent by mimemail and sending it using php's mail(). That displays the email just fine with no added css...

I've added mail.css as a blank file to my admin theme as suggested by some other posts I've found but that doesn't seem to effect it so I'm really not sure who might be doing this... simplenews or mimemail or maybe Drupal but I think that very unlikely.

Anyone have this happen to them? Any suggestions?

Thanks

Comments

mtpultz’s picture

It seems that dropping in a blank mail.css into your admin theme isn't enough to actually get Mimemail to not do any addition of css to your template. I found I had to override this preprocess function with nothing as well.

/**
 * A preprocess function for theme('mimemail_message').
 *
 * The $variables array initially contains the following arguments:
 * - $body:  The message body
 * - $mailkey:  The mailkey associated with the message
 *
 * See includes/mimemail.tpl.php for additional variables
 */

// ORIGINAL FUNCTION

function template_preprocess_mimemail_message(&$variables) {
  $theme = variable_get('theme_default', NULL);

  // Check for the existence of a mail.css file in the current theme folder
  if (!file_exists($styles)) {
    $styles = drupal_get_path('theme', $theme) .'/mail.css';
  }

  // If no mail.css was found, gather all style sheets
  if (!file_exists($styles)) {
    // embed a version of all style definitions
    $styles = preg_replace('|<link.*href="'. base_path()
                           .'([^"?]*)[?"].*|', '\1', drupal_get_css());
  }

  // Process each style sheet
  foreach (explode("\n", $styles) as $style) {
    if (file_exists($style)) $css .= file_get_contents($style);
  }

  $variables['css'] = str_replace(' ','', str_replace("\n", '', $css));
}

// OVERRIDDEN FUNCTION

function garland_preprocess_mimemail_message(&$variables) 
{
  // REMOVE ANY AND ALL THEMING MIMEMAIL ATTEMPTS TO IMPLEMENT
  // otherwise you'll get random css added to the newsletter
  $variables['css'] = "";
}

Hope this helps anyone else that might have this problem.

capoyeti’s picture

Thanks so much - this is exactly what I'm looking for... but...

I don't know which file to update with your code shown. Where is the preprocess function, and how do I override it?

Thanks again!

spyderboy’s picture

You can place this preprocess in template.tpl.php or better yet, in your own module. See http://drupal.org/node/173880 for more info

fehin’s picture

Place this part at the bottom of your template php. Change "garland" to the name of your theme.

>function garland_preprocess_mimemail_message(&$variables) 
{
  // REMOVE ANY AND ALL THEMING MIMEMAIL ATTEMPTS TO IMPLEMENT
  // otherwise you'll get random css added to the newsletter
  $variables['css'] = "";
}<
hm2k’s picture

I tried this and it didn't seem to work with my theme.

My theme is called l.

function l_preprocess_mimemail_message(&$variables)
{
  $variables['css'] = '';
}

However I found this which was useful...

http://drupal.org/node/346270#comment-2701264

fehin’s picture

Thank you. It worked for for me.

enap’s picture

This worked great for me, however after applying it the images used in my template's header & footer are not included (at all, checked the source). Has anyone had this issue?

JSCSJSCS’s picture

Thanks for posting. I could not figure out why my emails had all that extra CSS and why my emails looked terrible when I received them in Outlook. Now they are just the way I sent them!