Use Symfony Mailer API to send mails

Created on 13 April 2022, about 2 years ago
Updated 13 December 2023, 7 months ago

Problem/Motivation

Swiftmailer is now unsupported.

Proposed resolution

Use Symfony Mailer which is the natural replacement and it makes it much easier to send HTML mails. Already this first patch removes 2000 lines of code!

Remaining tasks

Get the tests working.

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom AdamPS

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.

  • πŸ‡¦πŸ‡²Armenia Alen Simonyan

    How we can skip actual sending of email? I mean the case when I want to pass all the phases, createParams, build, preRender etc, besides actual sending.

  • πŸ‡¦πŸ‡²Armenia Alen Simonyan

    I got an answer.

    If this is the case you need to set $email->setTransportDsn('null://null'); in postRender() function.
    @see https://symfony.com/doc/current/mailer.html#disabling-delivery

    /**
       * {@inheritdoc}
       */
      public function postRender(EmailInterface $email): void {
        if ($email->getSubType() == 'notifications') {
          // Prevent email sending.
          $email->setTransportDsn('null://null');
        }
      }
  • πŸ‡­πŸ‡ΊHungary Pasqualle πŸ‡­πŸ‡Ί Budapest

    I am a bit confused. The project page says: "HTML email can be sent by adding Drupal Symfony Mailer". If it works with symfony mailer why do we have this issue open?

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Also, under Administration > Configuration > Web services > Simplenews > Newsletter (/admin/config/services/simplenews/settings/newsletter) it says:

    Install Swift Mailer β†’ to send HTML emails or emails with attachments (both plain text and HTML).

    Should it be updated to say Drupal Symfony Mailer β†’ instead?

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I just tried with Symfony Mailer installed and can confirm that Simplenews works well. HTML elements such as images and links are sent and rendered as expected.

  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Should it be updated to say Drupal Symfony Mailer instead?

    Yes good point. In fact there are 13 matches of "swift" in various files in this module. I raised πŸ“Œ Replace references to swiftmailer with Drupal Symfony Mailer Active .

    If it works with symfony mailer why do we have this issue open?

    Good question.

    • Currently it works with this module sending mails through the "old" mail API, then Drupal Symfony Mailer (DSM) intercepts them and converts to the new API.
    • This issue would change this module to send directly through the new DSM API.

    I updated the title to make this clearer.

Production build 0.69.0 2024