symfony-docs icon indicating copy to clipboard operation
symfony-docs copied to clipboard

[Mailer] Sending Messages Async should not be default behavior

Open glukose opened this issue 2 years ago • 7 comments

Symfony version(s) affected

6.0

Description

Hello,

When creating a new symfony webapp project symfony new my_project_directory --webapp I couldn't send any email. The debug toolbar was displaying the email being queued but nothing was sent. I spent quite some time to check, url_encode et double check my MAILER_DSN value but without any success. No exception was raised either.

I then got to this chapter in the docs : https://symfony.com/doc/current/mailer.html#sending-messages-async which is clearly stating : "When you call $mailer->send($email), the email is sent to the transport immediately." but on the default configuration that is not the case.

I found out that if I comment the default configuration in messenger.yaml #Symfony\Component\Mailer\Messenger\SendEmailMessage: async or set it to null my email is sent normally.

This is quite confusing for someone used to send email with Symfony (which is the most common use case I believe).

Should the docs be changed to take into account the messenger default conf ? Or should the configuration file for messenger be changed ?

Cheers

How to reproduce

creating a new symfony webapp project symfony new my_project_directory --webapp and send an email like in https://symfony.com/doc/current/mailer.html#creating-sending-messages

Possible Solution

No response

Additional Context

No response

glukose avatar Mar 22 '22 09:03 glukose

If you take a look at:

  • https://github.com/symfony/symfony/blob/6.1/src/Symfony/Component/Mailer/Mailer.php#L41
  • https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.xml#L10 (sorry, i used the 4.4 version)

then, you can deduce that the async is only used if the messenger.default_bus service exists.

bruno-ds avatar Mar 23 '22 16:03 bruno-ds

I agree with @glukose, i tried to send emails and wondered why the emails was not send. I was stuck there for 1-2 Hours until i saw that the mails will be send async by default...

UtechtDustin avatar Mar 25 '22 11:03 UtechtDustin

I'm also having this issue. Is there a solution/workaround until the problem is fixed or the documentation is updated ?

Edit for future people having the same problem: Deleting messenger.yaml did the trick, I'm not sure how sending failure will be handled though

LyamD avatar May 30 '22 14:05 LyamD

Well, making it async when you have both messenger and mailer is a good default to me (sending emails asynchronously is a good idea as it avoids making your web page slower due to the time spent on SMTP). So to me this should be changed in the documentation. I suggest opening an issue (or even better a PR) on https://github.com/symfony/symfony-docs/

stof avatar May 30 '22 14:05 stof

I do understand why asynchronous emails are a good feature, not the simplest one though.

If your goal is to push messenger to be the default for sending emails, because it is included in the web_app skeleton and from your response it would be the default conf, then I guess the doc should reflect that.

But IMO it would mean rewriting a lot of this page https://symfony.com/doc/current/mailer.html#creating-sending-messages as you wouldn't be able to send a message as easily as advertised on the current page :

That's it! The message will be sent via the transport you configured.

To follow the logic that messenger is the new default way to send messages.

or do you think that just a small addition as "If you have symfony/messenger installed (it is included in the full web app starter pack) you'll need to change that conf line to xxx" would suffice ? It does seem like an extra step that is not efficient when you start a project and prone to errors.

glukose avatar May 30 '22 15:05 glukose

Updating the docs would be nice indeed.

fabpot avatar Jul 27 '22 15:07 fabpot

I've transferred this issue to the docs repo. Is anyone willing to work on a doc fix?

fabpot avatar Jul 27 '22 15:07 fabpot

adding a colored hint for the default async behavior to the mailer installation section https://symfony.com/doc/current/mailer.html#installation and to the messenger installation https://symfony.com/doc/current/messenger.html#installation would be good imho.

fafiebig avatar Jun 21 '23 10:06 fafiebig