Decorate MailManager instead of using a dedicated plugin

Created on 4 December 2017, over 6 years ago
Updated 1 June 2023, about 1 year ago

Problem/Motivation

Currently in order to use Maillog for mail logging you must set Maillog as the mail system plugin. And the Maillog plugin always delegates mail sending to the core PhpMail plugin.

This works well OK if all you want to do is swap out the core PhpMail plugin on dev environments in favour of a mail logging plugin. However, it prevents you from using any other mail plugin. For example, there are plugins that offer improvements over the core PhpMail plugin for particular email service providers (e.g. Sendgrid) and even for generic smtp (such as SwiftMailer).

Ideally Maillog should be able to log any mail, regardless of the configured mail plugin, and should not limit your choice for configured mail plugin.

Proposed resolution

Decorate the plugin.manager.mail service, so that mail logging can happen with any mail plugin.
Deprecate Maillog's plugin.

The one disadvantage of this approach is that it provides no way for sitebuilder's to enable mail logging only for mails sent by certain modules. It's all-or-nothing. However, that should be fine for the 95% or 99% use case.

Remaining tasks

Maintainer decision.

User interface changes

None.

API changes

The maillog mail plugin is deprecated.

Data model changes

None.

Original report

We wanted to use MailSystem to have SwiftMailer format emails, have Maillog log them, and then finally they get sent.
Swiftmailer formats the mails fine in its ::format() method, proxied by MailSystem's Adapter class.
However, it does not attach files or generate a plain-text version of the email until just before actually sending it in ::mail().
If we configure SwiftMailer as the sender in MailSystem we get attachments, but no logging. If we configure Maillog as the sender we get logging, but attachments, plain-text version, and some header processing is bypassed.

The main problem is that Maillog always delegates formatting and sending (if allowed) to the PhpMail class.

Original proposed solution:
Make the delegation configurable. Then we can tell Mailsstem to format using SwiftMailer and send using Maillog.
Maillog is then configured to delegate sending (back to) Swiftmailer (bypassing MailSystem).

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden TwoD Sweden

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.

Production build 0.69.0 2024