- 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.