FAQ / tips

Last updated on
12 June 2024

Prevent sending

  1. Use the GUI: create a policy with a "Skip sending"element.
  2. Using hooks:

    Before Symfony Mailer you would do something like this:

    function MYMODULE_mail_alter(&$message) {
      if ($message['key] == 'EMAIL_KEY'){
        if ($message['params']['user']->SOME_FIELD == 'SOME_VALUE'){
          // prevent sending of the Email.
          $message['send'] = FALSE;
        }
      }
    }
    

    With Symfony Mailer hook_mail_alter() is no longer invoked. See this page (SUBTYPE is the equivalent of KEY in the old terminology).

  3. Use Reroute Email module >= v2.3

Send as plain text

The way to do this is to generate an HTML email then subsequently convert it to plain text. It's necessary because this module is deeply based on Twig templates and rendering. These of course are HTML-based and they will persistently escape any plain text passed to them.

1) PENDING (not yet implemented) Using the GUI: create a policy with a "Send as plain text" element.

2) In code: see this issue for ideas.

Send mail with Postmark

  1. Download required libraries:
    composer require drupal/symfony_mailer symfony/postmark-mailer symfony/http-client
  2. Install Symfony Mailer:
    drush in symfony_mailer
  3. Add a DSN transport under /admin/config/system/mailer/transport:
    Type: DSN
    Label: Postmark
    DSN: postmark+api://ACTUAL_API_KEY@default
  4. Set the new "Type DSN", "Label Postmark" transport as default
  5. Make sure the Drupal system email matches the Postmark email Sender Signature

Bundler is undefined / email

The following error might be displayed when attempting to send an email using legacy hook_mail():

Error: Call to a member function fromArray() on null in Drupal\symfony_mailer\MailManagerReplacement->mail() (line 89 of modules/contrib/symfony_mailer/src/MailManagerReplacement.php).

If this happens it means that the hook_mail() implementation isn't recognized or the function is named incorrectly.

To fix the problem - verify that the hook_mail() function is named correctly for the module, e.g. if the custom module is named "mymodule" then the function would be named "mymodule_mail". Then, if it still does not work, rebuild the site's caches so that the system is aware of the function.

Help improve this page

Page status: No known problems

You can: