0

I've been using a combination of drupal_mail and mimemail to send out HTML formatted email; it's working fine. However, in some circumstances, I also need to be able to send out plaintext email -- not an empty HTML template, but a completely raw, plaintext message. I can't figure out how to disable mimemail for these messages, while leaving mimemail in place for the others. Any advice on how I might be able to do that? Thanks!

2

I've spent some time trying to achieve the same goal. I didn't find a lot of documentation on MimeMail module, I inspected the code and found a solution :

$message = drupal_mail('my_module', 'my_module_key', 'email@mail.com', $language,
 $params = [
   'subject' => $subject,
   'plain' => true,
   'plaintext' => $mailBody,
           ]);

You just need to use 'plain' => true and put your mail content in 'plaintext' => $mailBody

0

Figured it out, I think:

(1) For some module, create a mail template to handle the plaintext requests, the details of which depend on how you're putting together your messages. For me, this works:

function mymodule_mail($key, &$message, $params) {
     switch ($key) {
          ...
          case 'plaintext':
               $message['subject'] = $params['message_header'];
               $message['body'] = $params['message_body'];
               break;
     }
}

(2) Use mailsystem_set to set up an entry in the mail_system variable that points to the combined module and the key -- mymodule_plaintext in this case -- and that specifies the mail system DefaultMailSystem:

  module_load_include('module', 'mailsystem');
  mailsystem_set(
    array(
      'vr_random_plaintext' => 'DefaultMailSystem',
    )
  );

(See mimemail.module for tips on doing this; since it only needs to be run once, they recommend doing it in a hook_enable handler.)

(3) You should then be able to send plaintext messages by calling drupal_mail() and specifying mymodule and plaintext as the module and mail_template for the message.

This is working for me, although I may have glossed over a thing or two. If there are questions, post away...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.