-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer][DX] Unable to set global sender email #31733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably related to the fact that the framework integration of the component still needs to be added #31592 (comment) |
It may be related to some missing framework integration, but on a component level, due to the fact that the event is dispatched after the "from" sanity check (https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Mailer/Transport/AbstractTransport.php#L60-L69) - it's not possible to create messages without a from and then using a listener to add it. Or said differently, even if I think that |
Actually, even the proposed solution (of using a dummy email) doesn't work for me. Well, it does correctly set the Sender, but there is not currently a way to globally set the From, except to create your own listener. |
#31774 should fix this issue, can you confirm? |
@fabpot Now I've got
|
@BoShurik Can you share a small project with me so that I can reproduce on my side? |
@BoShurik You don't have a |
@fabpot thanks. Now it works. As I understand, this common task will be solved by |
Right, you will soon be able to configure it without registering the listener yourself. |
…sageListener (fabpot) This PR was merged into the 4.3 branch. Discussion ---------- [Mailer] Fix the possibility to set a From header from MessageListener | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #31733 | License | MIT | Doc PR | n/a <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> Commits ------- f4254e6 [Mailer] fixed the possibility to set a From header from MessageListener
… from config (Devristo) This PR was squashed before being merged into the 4.4 branch (closes #32081). Discussion ---------- [WIP][Mailer] Overwrite envelope sender and recipients from config | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #31592 #31733 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> # Description This MR adds the following configuration, example: ```yaml # config/packages/mailer.yaml framework: mailer: envelope: sender: 'sender@example.org' recipients: ['redirected@example.org'] ``` In turn the `\Symfony\Component\Mailer\EventListener\EnvelopeListener` will be configured to alter the sender and recipient addresses before the message has been sent. Note: it will only alter the envelope, thus rerouting the message to the correct mailbox. However the message itself will still have the original 'from' and 'to' headers. # Todos - [x] Alter configuration and dependency injection - [x] Create test case - [ ] Update XML config schema? - [ ] Doc PR <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> Commits ------- 8e0c800 [WIP][Mailer] Overwrite envelope sender and recipients from config
Currently looks like its not possible to set global sender without setting sender in message
I tried to set sender globally with:
and create message with:
but got
Cannot send message without a valid envelope. (Unable to determine the sender of the message.)
becauseMessageEvent
dispatched afterSmtpEnvelop
created in AbstractTransportso I need to fill sender with a dummy email:
The text was updated successfully, but these errors were encountered: