Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] Add possibility to disable message bus #32488

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

Closed
wtorsi opened this issue Jul 10, 2019 · 2 comments
Closed

[Mailer] Add possibility to disable message bus #32488

wtorsi opened this issue Jul 10, 2019 · 2 comments

Comments

@wtorsi
Copy link

wtorsi commented Jul 10, 2019

As the result of my investigations here #32487, i found, that when messenger is enabled, there is no possibility to disable it in mailer and this can cause problems.
For example when trying to retry failed TemplatedEmail message, mailer sends it to the next bus, and then serializer tries to call getBody from message, but there is no html and text parameters in instance yet, because BodyRenderer::render was not called.
And as the result you will see LogicException from Email:427

I don't know how to better solve this issue, but in my case i've just relinked MailerInterface to my custom mailer without bus inside.

#services/mailer.yaml
Symfony\Component\Mailer\MailerInterface: '@Mailer\Mailer'
@fabpot
Copy link
Member

fabpot commented Jul 17, 2019

Having the Messenger component is not enough for the emails to be sent via a bus. If you want to disable sending emails via the messenger, you need to remove the configuration for the SendEmailMessage class in your configuration.

@fabpot fabpot closed this as completed Jul 17, 2019
@alexislefebvre
Copy link
Contributor

Having the Messenger component is not enough for the emails to be sent via a bus. If you want to disable sending emails via the messenger, you need to remove the configuration for the SendEmailMessage class in your configuration.

Thanks, that really helped in a project with Symfony dependencies locked to 4.4 and symfony/mailer:^5.4.

We wanted to send mails asynchronously in prod and asynchronously in dev and test, so that we didn't have to call messenger:consume during tests to send emails. But we weren't able to use message_bus: false since it requires symfony/framework-bundle >= 5.1.

So we used this config:

# config/packages/messenger.yaml
framework:
    messenger:
        #

        transports:
            async_import: '%env(MESSENGER_TRANSPORT_DSN)%'
            async_mailer: '%env(MESSENGER_TRANSPORT_DSN)%'

        routing:
            'App\Message\PriceImport': async_import
# config/packages/prod/messenger.yaml
framework:
    messenger:
        routing:
            'App\Message\PriceImport': async_import
            # use “…SendEmailMessage” only on prod environments,
            # so that emails are sent asynchronously on prod,
            # and synchronously on other environments
            'Symfony\Component\Mailer\Messenger\SendEmailMessage': async_mailer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants