Problem
I'm trying to style an email sent with drupal_mail. Sometimes it works, other times it doesn't and I can't work out why.
I'm running mail system, SMTP and mimemail:
Mail system sets up: SMTP for sending and mimemail for styling.
In the mimemail options include stylesheets is disabled because it's found mail.css in my theme. Mime mail CSS compressor is enabled because people use hotmail and gmail.
Condition 1
User uses form to send email, this works as expected I receive a styled email in gmail.
$message = drupal_mail('module_1', 'notify', $email, language_default(), $params);
function module_1_mail($key, &$message, $params) {
$title = check_plain($_SESSION['title']);
$message['headers']['MIME-Version'] = '1.0';
$message['headers']['Content-Type'] = 'multipart/mixed; text/html; charset=UTF-8; format=flowed;';
$message['subject'] = t('Email subject plus ').$title;
$message['body'][] = "Body text goes here";
$message['params']['attachments'] = $params;
}
Condition 2
The user uses another form which schedules a rule action which sends an email some time later. This doesn't receive any styling despite seeming identical for all intents and purposes.
$message = drupal_mail('rules_module', 'notify', $user->mail, language_default(), $params);
function rules_module_mail($key, &$message, $params) {
$message['headers']['MIME-Version'] = '1.0';
$message['headers']['Content-Type'] = 'multipart/mixed; text/html; charset=UTF-8; format=flowed;';
$message['subject'] = t('Here is a (@location)', array('@location' => $params['location']));
$message['body'][] = 'This is some body text';
}
Could rules somehow affect the calling of a stylesheet? Am I missing something obvious?