Module now silently falls back to null transport if there is no valid transport

Created on 29 January 2024, 8 months ago
Updated 24 February 2024, 7 months ago

Problem/Motivation

Since ✨ Add Symfony Messenger support for async messsages (emails as queues) Needs review , due to the new transport factory services/logic, invalid transports are automatically filtered out and it falls back to the null transport, so mails are not send without any logs or feedback.

Before πŸ› SymfonyMailer::mail should handle other exception types Fixed , such an invallid transport caused an exception, but that issue was supposed to change that. It doesn't look like the patch was correct though or there was a refactoring because it didn't actually work properly.

For context, we use config overrides to only enable mail transport on production environments. Before the async issue and when using swiftmailer/default mail transport, invalid e-mails caused an error so you knew e-mails weren't going out. Now with version 1.0.2+, there's just nothing.

That's in some ways good, because that standard Drupal message that shows up often confused our clients, but having no feedback is going to confuse developers I think when they do expect working e-mails.

Steps to reproduce

Proposed resolution

Maybe log a warning message if there are configured transports but none are valid and it falls back to null?

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

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

Merge Requests

Comments & Activities

  • Issue created by @Berdir
  • First commit to issue fork.
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    The warning in the log could work, but I thought of another way. What if we create a new ErrorTransport and return that from TransportsFactory in this case? The ErrorTransport's job is simply to throw an Exception any time someone tries to send an email. That exception is then caught by the work we did in πŸ› SymfonyMailer::mail should handle other exception types Fixed , and the normal email failed message is displayed. A more detailed message from the exception is in the logs.

    I tested this, and it seems to work. I added an MR to this issue. Can you test it to see if it works for your use case?

    Not directly related to this, but FYI, we did remove the ability to delete your default transport in πŸ› Setting symfony_mailer_lite.settings.default_transport not guaranteed to be set Fixed . That may affect the way you're configuring your sites, since it's now harder to get into a situation where you have no transports.

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    I just want to document this, really. This isn't an issue for us anymore, the reason we initially had the exception and then the null transport is that our transport existed but was invalid (an smpt transport without the required host field). We changed it to host localhost now, which doesn't work, but is technically valid config, tries to send, fails and then throws an exception, resulting in the old behaviour if displaying an error message when mail configuration is invalid/disabled.

    I suppose an error transport works too, whatever you are comfortable with as a maintainer :)

  • Pipeline finished with Skipped
    7 months ago
    #92139
  • Status changed to Fixed 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States zengenuity

    I merged this change. Now, when no transports are configured, the system will display the generic core email failed error. The detailed message about the unconfigured transports is available in the error log.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024