Skip to content
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

Allow to use "symfony/mailer" within Mailer #1263

Merged
merged 1 commit into from
Nov 23, 2020

Conversation

phansys
Copy link
Member

@phansys phansys commented Oct 25, 2020

Subject

Allow to use "symfony/mailer" within Mailer.

I am targeting this branch, because this change respects BC.

Closes #1193.

Changelog

### Added
- Support for "symfony/mailer" in `Sonata\UserBundle\Mailer\Mailer`.
### Deprecated
- Support for "swiftmailer/swiftmailer" in `Sonata\UserBundle\Mailer\Mailer`.

To do

  • Update the tests;
  • Add an upgrade note.

Copy link
Member

@jordisala1991 jordisala1991 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Dont we have to change the DI to inject the symfony mailer?

}

$this->mailer->send(
(new Email())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using templateEmail to have direct support for twig using the template name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will not possible in a transparent way, since the Twig template is currently providing the subject and the body:

$renderedLines = preg_split('/\R/', trim($rendered), 2, PREG_SPLIT_NO_EMPTY);
        $subject = array_shift($renderedLines);
        $body = implode('', $renderedLines);

@phansys
Copy link
Member Author

phansys commented Oct 25, 2020

Dont we have to change the DI to inject the symfony mailer?

I think there is no need to change the DI, since the service sonata.user.mailer.default is expecting the mailer service as argument 3, and the symfony/framework-bundle is registering this service when the symfony/mailer component is installed and the framework.mailer configuration is enabled.

<service id="sonata.user.mailer.default" class="Sonata\UserBundle\Mailer\Mailer">
<argument type="service" id="router"/>
<argument type="service" id="twig"/>
<argument type="service" id="mailer"/>
<argument>%fos_user.resetting.email.from_email%</argument>
<argument>%fos_user.resetting.email.template%</argument>
</service>

@phansys phansys force-pushed the issue_1193 branch 3 times, most recently from 0dac983 to f2c236c Compare October 25, 2020 23:42
@phansys phansys marked this pull request as ready for review October 25, 2020 23:45
@phansys phansys requested review from jordisala1991 and a team October 25, 2020 23:45
VincentLanglet
VincentLanglet previously approved these changes Oct 26, 2020
@VincentLanglet VincentLanglet requested a review from a team October 26, 2020 20:46
@phansys phansys requested review from jordisala1991 and removed request for jordisala1991 October 27, 2020 12:23
@phansys
Copy link
Member Author

phansys commented Oct 28, 2020

Since in my projects I'm using symfony/mailer and symfony/framework-bundle (which overrides the mailer service registered previously by swiftmailer/swiftmailer, it also resolves the following exception:

Invalid definition for service "Sonata\UserBundle\Action\SendEmailAction": argument 3 of "Sonata\UserBundle\Mailer\Mailer::__construct" accepts "Swift_Mailer", "Symfony\Component\Mailer\Mailer" passed.

@VincentLanglet VincentLanglet requested a review from a team November 14, 2020 23:56
@phansys
Copy link
Member Author

phansys commented Nov 16, 2020

Friendly ping @jordisala1991.

@phansys phansys merged commit ecc961b into sonata-project:4.x Nov 23, 2020
@phansys phansys deleted the issue_1193 branch November 23, 2020 22:44
@SonataCI
Copy link
Collaborator

Ok @phansys,

I requested a new release for SonataUserBundle via Slack in #releases channel 👍

If you want to get notified about new releases, make sure to follow SonataNews on Twitter!

@sonata-project sonata-project deleted a comment from phansys Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Symfony\Component\Mailer\Mailer (mailgun, sendgrid etc.) as a mailer
5 participants