Reset SMTP configuration to default values after sending an email

Created on 18 October 2024, 3 months 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
  • πŸ‡©πŸ‡ͺ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.

    • gbyte β†’ committed 8066e35b on 2.x
      Issue #3481723 by leontin, gbyte: Reset SMTP configuration to default...
  • πŸ‡©πŸ‡ͺGermany gbyte Berlin

    Good catch @leontin!

    Thanks for the patch; I found it cleaner however to remove the state from the service and just reset the SMTP configuration right after sending each email. This seems to be working but I'd appreciate you double checking. Also if you find the time, feel free to write a test for this.

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

Production build 0.71.5 2024