Problem
The problem occurs when upgrading from v1.2.x when both the following conditions are true:
- symfony_mailer_bc was enabled
- Some Mailer configuration import operations had been ignored (neither imported or skipped)
For more detail, see #7.
Workaround
Visit the mailer overrides page, and correct the settings - enable or import any overrides that are missing. Warning: this resets any changes you have made to the default configuration.
Proposed resolution
Fix the update hook as described in #8.
Original summary
On Override tab I enabled & imported User items.
And now the user tokens in the password reset emails are not replaced. Only [site:xxx] are replaced.
Explanation why it happens:
Password reset emails provide their own 'user' context token data. And user tokens are replaced AFTER text formatters are applied to the text.
If text formatters use "Replace tokens" with "Replace empty values" option checked, tokens will be deleted from text and mail provider will have text without tokens already.
What can I do?
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | symfony_mailer.update-overrides.3392446-17.patch | 2.08 KB | vlad.dancer |
Comments
Comment #2
adamps commentedIt works for me.
UserEmailBuilder::buildpasses the callbackuser_mail_tokens.Comment #3
nojj commentedafter updating to V1.3.2 I seem to have the same issue.
Tokens are not replaced.
Even [site:name] is not replaced.
Any ideas?
Edit:
for me it was the policy of User Registration Password which was not activated by default. I had to activate override and enter the message again. now tokens are working.
Comment #4
vlad.dancerOk. I had this issue too.
I think after updating symfony_mailer from 1.2.1 to 1.3.1 the new user policies from symfony_mailer were added but not enabled.
And
LegacyEmailBuilderwas used insymfony_mailer_mailer_builder_info_alterto build emails with user policies becauseoverride_manager->isEnabledcan't find overrides in$\Drupal\symfony_mailer\Processor\OverrideManager::isEnabled $this->configFactory->get('symfony_mailer.settings')->get('override').So @nojj is right in order to fix this issue we need to enable/disable user policies override.
Comment #5
vlad.dancerChanging priority since register user/restore password features are very important on many sites.
Comment #6
adamps commentedI still don't understand how to reproduce the bug. #3 talks about User Registration Password. #4 talks about updating from v1.2. Neither one has a precise sequence of steps I can follow. The issue summary is totally missing the "Steps to reproduce" section which is essential for a bug report.
The following are both by design, not a bug
Comment #7
vlad.dancerI think there will be more bug reports in this issue.
I came to this issue when detected that user related emails were with raw tokens. But other people can detect this issue on different emails.
Steps to reproduce:
composer require 'drupal/symfony_mailer:1.2.1' --no-audit. Installing Modulesdrush en symfony_mailerdrush en symfony_mailer_bccomposer require 'drupal/symfony_mailer:1.3.1' && drush crSummary
If you used 1.2.1 mailer with symfony_mailer_bc and then updated to 1.3+ using drush (without visiting admin interface) you'll end up with having mailer policies but with disabled overrides for them:
Suggested way to fix
Provide runtime check in
symfony_mailer_requirementsto compare if mail policies exist andsymfony_mailer.settings.overrideis empty.If that was detected then suggest user to re-enable policy overrides or delete that policies.
Let me know if you need additional information or access to the test drupal instance.
Comment #8
vlad.dancerComment #9
adamps commentedGreat thanks for a detailed report and excellent debugging. The override setting is initialised in
symfony_mailer_update_10008(). However if there was never any import or skip, then the old import key-value wasn't set, so the update hook doesn't work.It's perfectly allowed to have a policy but no override. The policy could be to add a bcc, skip sending the message, or log it. So we can't rely on existing policy. Also we can't assume the overrides available now were also available in v1.2 as this module added commerce in v1.3.
I believe the correct fix is in the update hook.
Comment #10
vlad.dancerHere is requirement check that can inform users to delete odd policies manually:
BTW: thanks for keeping original summary because lots of people will search by "User tokens in Password reset email are not replaced".
Comment #11
adamps commentedPatch not fully tested yet
Comment #12
adamps commented#10 is an interesting idea thanks. However (as I said in #9) it's perfectly allowed to have a policy but no override. The policy could be to add a bcc, skip sending the message, or log it.
Comment #13
vlad.dancerParseError: syntax error, unexpected token ";" in /var/www/html/web/modules/contrib/symfony_mailer/symfony_mailer.install on line 202 #0 /var/www/html/web/core/includes/install.inc(87): Drupal\Core\Extension\ModuleHandler->loadInclude()
Comment #14
vlad.dancerThank you @AdamPS, your fix works for me.
Just fixed syntax error and notices in your patch:
Comment #15
vlad.dancerI've copied code from the patch not fully)
Now should work.
Comment #16
vlad.dancerHeh. Hope this is last one.
Comment #17
vlad.dancerAdded ending line-feed.
Comment #19
adamps commentedGreat thanks
Comment #20
adamps commentedComment #21
giuseppe87 commentedAm I wrong or this patch approach doesn't consider the case the updates of 1.4.0-beta1 has been already done? Because the
symfony_mailer_update_10008symfony_mailer_update_10009would have already run.From a quick test setting the version to a previous state, e.g.
drush ev "\Drupal::service('update.update_hook_registry')->setInstalledVersion('symfony_mailer', 10007);"and re-do the updates should work, but please correct me if this it is not right or necessary.
Comment #22
adamps commentedFor sites that have already upgraded to 1.4.0-beta1, then
symfony_mailer_update_10009has removed thesymfony_mailer_bcmodule, sosymfony_mailer_update_10008would have no effect. I can't see any possible automatic fix as the code can't tell ifsymfony_mailer_bcwas previously installed - sorry.The code in #21 should work if you manually enable
symfony_mailer_bcagain first.Comment #23
giuseppe87 commentedYes, I can confirm that
fixed the token replacement in my site, even if already run the updates with 1-4.0-beta1.
Thank you.
Comment #24
michèle commentedI can confirm #23, too. Thank you!
But bear in mind, that you have to
drush en symfony_mailer_bcagain, after updatedb, as 10007 will disable the module.
Comment #25
kreatil commentedIn my case, the method described under #23 also worked. However, afterwards I had to reactivate symfony_mailer_bc and go to admin/config/system/mailer/override and perform "User" > "Enable & Import". Why symfony_mailer_bc now has to be active again, even though it was declared as obsolete, is beyond me.