-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Simplify getting SentMessage information after send #42108
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
Thank you for this issue. |
This would then make it likely that some code will be written that would break if you turn on async sending. And from a performance point of view, you likely want to turn on async sending. So that looks like a bad idea to me. |
same boat :) what if we split the API? either by method, or thru argument. |
I'd like to +1 this proposal. How exactly it's implemented – whether the Mailer interface returns the SentMessage object or there is a triggered event – does not matter to me. The use cases that are important for me:
For some projects, I still need to use swiftmailer for this reason. |
@stof sorry if the comparison is not correct ... but in the HttpClient component we return a response object immediately even if the HTTP request is async. We could do the same here: always returns a (1) If technically possible, do the same as HttpClient and implement the methods in a way that for async emails you just need to wait until you receive a response form the server. |
I would love to have an Event dispatched after the Message is sent. Of course this Event should contain the |
@javiereguiluz the HttpClient does concurrent requests in the same PHP process. But it does not delegate the request sending to a Messenger worker running in a different process. That's not the same kind of async (there was a talk about async PHP at the Symfony Live Paris 2022, that was showing the various kinds of async in its intro) |
Dispatching events is the best/only way to fix this one. See #47080. |
This PR was merged into the 6.2 branch. Discussion ---------- [Mailer] Add new events | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #42108 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | Dispatching 2 new events: `SentMessageEvent` and `FailedMessageEvent` when sending an email. It allows acting on the `SentMessage` or the "initial" message in case of a failure. Commits ------- d1138b2 [Mailer] Add new events
…geEvent` (wkania) This PR was merged into the 6.4 branch. Discussion ---------- [Mailer] Mention the `SentMessageEvent` and `FailedMessageEvent` The symfony/symfony#47080 PR was created to solve the problem of [debugging](symfony/symfony#37570) and to get [information](symfony/symfony#42108) about email after it was sent. The section about [debugging](https://symfony.com/doc/current/mailer.html#debugging-emails) does not mention those events. Added some links for better navigation. For example what debug returns: ``` < 220 ESMTP SYMFONY.COM > EHLO [127.0.0.1] < 250-smtp.symfony.com < 250-PIPELINING < 250-SIZE 157286400 < 250-AUTH PLAIN LOGIN PLAIN LOGIN PLAIN LOGIN < 250-AUTH=PLAIN LOGIN PLAIN LOGIN PLAIN LOGIN < 250-ENHANCEDSTATUSCODES < 250-8BITMIME < 250 SMTPUTF8 > AUTH LOGIN < 334 VXNlcm5hbWU6 > ZXhhbXBsZUBzeW1mb255LmNvbQ== < 334 UGFzc3dvcmQ6 > U3ltcGhvbnkg.aXMgQXdlc29tZQ== < 235 2.7.0 Authentication successful > MAIL FROM:<[email protected]> < 250 2.1.0 Ok > RCPT TO:<[email protected]> < 250 2.1.5 Ok > DATA < 354 End data with <CR><LF>.<CR><LF> > . < 250 OK. ID: a20fb6ebbc54d22b ``` P.S. I see that the checks now can find repeated words: ``` mailer.rst ✘ 1765: The word "the" is used more times in a row. -> ``FailedMessageEvent`` allows acting on the the initial message in case of a failure and some ``` Commits ------- 8e3c1db [Mailer] Mention the SentMessageEvent and FailedMessageEvent in the debug section
Description
In some cases, you may need to get
SentMessage
information after send.As the docs say
SentMessage
generates byTransportInterface
and NOT available through the Mailer by itself.The reason for this is understandable -
Mailer
can't just returnSentMessage
as it can work async (through the Messenger)I've seen related issues and rejected PR's (breaking BC), but still believe that Symfony should provide better DX in this case.
Example
In my case, I needed to get the Mailgun mail id to track it after sending it.
I ended up with this workaround - not brilliant as DX.
Later I faced another solution - to use directly
TransportInformation
, but again, it's not what you expecting from Mailer.Proposal
As a developer, I expect to deal with
Mailer
as the main Facade component, notTransport
, therefore I think this PR makes sense for the next major version where we can break BC and make return type?SentMessage
for sync sending.As for now, we can make a new Event called MessageSentEvent that will provide SentMessage for minor version updates, and still useful for async mode.
And dispatch this Event after transport sends a message:
After that, it becomes easy to subscribe to this event and process SentMessage information.
The text was updated successfully, but these errors were encountered: