Reset SMTP configuration to default values after sending an email

Created on 18 October 2024, 28 days ago

Problem/Motivation

The SMTP settings are not reset to their default after sending an email.
If multiple emails are sent in the same request, all emails after the one that uses custom credentials will continue to use those same credentials.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @leontin
  • Merge request !1refs #3481723 reset SMTP config to default → (Open) created by leontin
  • 🇩🇪Germany gbyte Berlin

    Let's continue this in 2.x, as Drupal 8/9 is not supported anymore.

    I haven't tested the code, but why would different emails use same credentials? The new mail data arrives as the message parameter within the mail() function having new values and so changing of the values should be evaluated anew depending on the message ID?

  • In the current implementation, the SMTP settings are overridden globally within the request context when $this->smtpConfig->setSettingsOverride($config) is called for custom credentials. This override does not automatically reset after each email is sent. Therefore, if multiple emails are sent in a single request, they will all continue to use the overridden credentials unless explicitly reset.

    The mail() function in this setup doesn’t independently refresh the SMTP configuration for each message based on the message ID. Instead, it relies on the active configuration within the request scope. So, without a manual reset to the default settings after each email, any additional emails sent within the same request will retain the credentials from the first override.

    To prevent this unintended persistence, we’d need to explicitly reset the SMTP configuration to its defaults after each email or apply a different instance-based configuration that isolates credentials per email.

    Please test and let me know how it went.

Production build 0.71.5 2024