Drupal 8, Webform module : send html mail with plain text mime/alternative

Viewed 354

We use Webform Drupal 8 module to handle newsletter subscription on a website. An html formatted email is sent to confirm subscription. Unfortunately, this email is sent with only content-type:text/html, and you know how picky Spamassassin is about this. It's a real deliverability issue. We'd like to be able to send that email with a content-type:multipart/alternative, with 2 parts : one with text/html content-type and one with text/plain. How can we do this ? We installed "mail system" and "mime mail" modules, but we can't figure out how to use them, or even if it's the right solution. Has anyone ever managed to do this?

1 Answers

Have a look at this module.

Once mime-mail module is enabled you can modify the emails send by Drupal using hook_mail_alter hook (see here) and add plain-text version.

In a custom module, in your mymodule.module file you can do something like this:

/**
 * Implements hook_mail_alter().
 */
function mymodule_mail_alter(&$message) {

  //to specify which email need altering based on id
  //without this all emails send will be altered
  if (isset($message['id']) && $message['id'] == 'contact_page_mail') {
    
    //set plain text
    $message['params']['plaintext']= "HTML support needed";
  }
}
Related