No mail with symfony_mailer

Created on 4 March 2022, over 3 years ago
Updated 1 June 2023, about 2 years ago

Problem/Motivation

When i send mail with symfony_mailer, no mail are displayed in dashboard.
Mails are sent successfully.

thank

🐛 Bug report
Status

Needs work

Version

1.2

Component

Code

Created by

🇮🇹Italy trickfun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy trickfun

    I fix the patch.
    Some wrong if conditions preventing save messages into mail safety table.

  • 🇮🇹Italy trickfun

    this is the patch for 8.2 version

  • 🇮🇹Italy trickfun

    Sorry, the patch is wrong.
    this is the right, i hope

  • 🇧🇪Belgium flyke

    I can conform this works on 8.x-1.2
    - Apply patch
    - Clear caches (drush cr)
    - Visit Settings > System > Mailer (/admin/config/system/mailer)
    - Edit *All* (/admin/config/system/mailer/policy/_)
    - From the dropdown, select 'Mail Safety' and add it

  • 🇸🇪Sweden agogo

    Thanks for the patch! Also works with 2.0. (#13)

    A small note is that the patch forces all mails to not be sent when not using a/the default mail address by setting setTransportDsn as null. I had to make a copy of the patch and remove that part (+ the setReplyTo setting that is there for some reason).

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Thanks for the patch, it is a valuable POC. Also for #15.

    The adjuster approach has the downside though, that i must add an adjuster.

    What i want as a site owner is sth like a simple config override setting to set in all dev environments and when i see that setting, i have no fear that a customer gets an ouch mail (which is the promise of this module).

    Maybe leveraging hook_mailer_alter helps here.

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Feedback from AdamPS (Maintainer of Drupal Symfony Mailer) in the related issue:

    The patch on #3267796: No mail with symfony_mailer seems like the wrong approach - as you say it requires adding an adjuster. Presumably the module previously used hook_mail_alter() and it should now use the new hooks and throw a SkipSending.

  • 🇮🇳India msuthars Pune

    I have integrated the mail_safety with symfony_mailer using the following snippet:

    /**
     * Implements hook_mailer_build().
     */
    function YourModule_mailer_build(\Drupal\symfony_mailer\EmailInterface $email) {
      $config = \Drupal::config('mail_safety.settings');
    
      if ($config->get('send_mail_to_dashboard')) {
        try {
          $params = $email->getParams();
          $message = [
            'key' => $params['legacy_message']['key'],
            'module' => $params['legacy_message']['module'],
            'to' => !empty($config->get('send_mail_to_default_mail')) ? $config->get('send_mail_to_default_mail') : $params['legacy_message']['to'],
            'from' => $params['legacy_message']['module'],
            'langcode' => $params['legacy_message']['langcode'],
            'subject' => $params['legacy_message']['params']['subject'] ?? NULL,
            'body' => [$params['legacy_message']['params']['body'] ?? MailFormatHelper::htmlToText($params['legacy_message']['params']['body']->__toString())],
            'headers' => $email->getHeaders()->toArray(),
            'send' => FALSE,
          ];
         \Drupal\mail_safety\Controller\MailSafetyController::insert($message);
        }
        catch (\Exception $e) {
          \Drupal::logger('YourModuleLog')->error($e->getMessage());
        }
      }
    
      if ($config->get('enabled') && $config->get('send_mail_to_default_mail')) {
        $email->setTo($config->get('default_mail_address'));
      }
    
      if ($config->get('enabled') && !$config->get('send_mail_to_default_mail')) {
        $email->addProcessor(function ($email) {
          throw new \Drupal\symfony_mailer\Exception\SkipMailException('Email sending skipped by mail_safety.');
        }, \Drupal\symfony_mailer\EmailInterface::PHASE_BUILD, 0);
      }
    }
    
Production build 0.71.5 2024