How can I route automated emails through an email function in my module? I was unable to get HTML mail to use a template properly, so I have a mymodule_mail function that sends emails when a response is required from the user

function billiondollar_mail($key, &amp;$message, $params) {
global $base_url;

$message['headers'] = array(
    'MIME-Version' =&gt; '1.0',
    'Return-Path' =&gt; 'xx@xx.com',
    'Content-Type' =&gt; 'text/html; charset=UTF-8; format=flowed',
    'From' =&gt; 'XXXX &lt;xx@xx.com&gt;',
    'Content-Transfer-Encoding' =&gt; '8Bit',
    'X-Mailer' =&gt; 'Drupal'
);


I have a switch case on $key that loads in html header and footer plus the email body.

I'm wondering if there's some way I can make the system emails (some sent via trigger/actions and the registration confirmation ones) use that same system. Right now they are in plain text, which is incongruous with the rest of the system.

If I can get them using that hook function I will need to know what $key value it would have and how to insert the message content.. presumably one of the $params
I think this is what you're looking for:

http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_mail_alter/7

"hook_mail_alter() allows modification of email messages created and sent with drupal_mail()... All core modules use drupal_mail() for messaging, it is best practice but not mandatory in contributed modules."