-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Add advanced logger #37570
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
I think that you are looking for this: https://symfony.com/doc/current/mailer.html#debugging-emails |
Yeah I know that - my idea is to integrate it in the Framework Bundle. Currently this is what I did for debugging:
And that overrides: |
And even that's not enough - sometimes the Debug info is missing at all. I had to refactor it like that to get missing debug info.
The problem is that I get
Randomly. |
In the end - it was because timeout.
It's good to have these configurable. |
Having the number of bytes sent over the wire could be useful for logging/debugging (from |
Thank you for this suggestion. |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hi bot, il do would like this feature (number of bytes sent over the wire) 😀. |
What is also very useful and needed is to log the message ID of the remote system. See also swiftmailer/swiftmailer#913 |
Thank you for this suggestion. |
Could I get a reply or should I close this? |
Still interested, but maybe already solved? I find it very important to log the message ID. |
#47080 adds a new FailureMessageEvent that you can listen to, making logging a bit easier. |
Thank you for this suggestion. |
Logging the message ID would still be great - without the need for verbose debug output :-) |
I'm assuming this would stand-in for Swift_Mailer's loggers. https://swiftmailer.symfony.com/docs/plugins.html#logger-plugin Does It's also worth mentioning that the Symfony docs aren't super helpful if you're not using the framework. |
Also stumbled across this issue today. $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this->logger)); I could not find a replacement for the DependencyContainer either. $instance = Swift_DependencyContainer::getInstance();
$instance
->register('mime.charstream')
->asNewInstanceOf('Sys\\Bundle\\Portal\\Component\\Swift\\CharacterStream\\MbCharacterStream')
->withDependencies( [ 'mime.characterreaderfactory', 'properties.charset' ] ); What is the new Way of requesting the DSN and MDN with the Symfony-Mailer? https://github.com/search?q=repo%3Aswiftmailer%2Fswiftmailer+setReadReceiptTo&type=code $mailer->registerPlugin(new DsnPlugin([new NotifyHandler('success,failure')])); https://gist.github.com/Orgoth/22fb841c6887b1cfbfe58eba79d37642 https://datatracker.ietf.org/doc/html/rfc8098 |
@Orgoth We ended up using our adapter service for handling this. It'd have been nice to have provided some more clear direction when Swift_Mailer was dropped, as to what the recommended implementation equivalent is for unsupported functionality. |
Well, symfony/mailer is not a drop-in replacement for Swiftmailer. It has a totally different architecture. Swiftmailer plugins indeed do not fit in this architecture. Symfony has different kind of extension points (and maybe new ones would be useful, but they should be requested as dedicated feature request with a use case, not just "I want to be able to use my Swiftmailer plugins" which is a no-go as that's not possible). Note that the ReadReceiptTo feature is really just about adding the |
@oojacoboo logging can be implemented using events. We have SentMessageEvent for successful ones and FailureMessageEvent for failures. |
@stof Thank you for the clarification. Other projects have solved the transition better by pointing out which functions can or should be used instead. But just setting it completely without a migration guide to pick up the developers is very unattractive. I just need to explain this to my employer, why it is taking so long and what else needs to be done to get back to the same level as with SwiftMailer. Edit: In particular the plugin system! |
@Orgoth symfony/mailer is a totally different project than swiftmailer. We don't have a 1:1 mapping of each method. that's why there is no such deprecation warnings on Swifmailer methods. And symfony/mailer can be used standalone. but we indeed miss the documentation about that (which is mostly about documenting the wiring done to instantiate a Mailer, as done by FrameworkBundle). The documentation of the new component focused on the usage in the framework first and nobody has written a doc about the standalone setup yet.
Since the creation of the component, you are literally the first one asking us for a replacement for the And we cannot just bring the Swiftmailer plugin system in symfony/mailer. That plugin system was closely related to the architecture of swiftmailer. The available extension points in symfony/mailer are following a different architecture. That's why a previous comment of mine said that if we are missing some extension points to solve some use cases, new feature requests should be opened as dedicated issues explaining that use case so that we can find the appropriate extension point for that. |
For all others who come here and use the mailer as a standalone.Regarding the advanced logging:
The background is, with the SwiftMailer still a separate Mailer class was used, this is no longer necessary here. Just do it yourself. $transfer = new EsmtpTransport($auth['host'],$auth['port'],null,null,$smtpLogger);
$transfer->setUsername($auth['user']);
$transfer->setPassword($auth['pass']);
$sentMessage = $transfer->send($message);
$sentMessage->getDebug();
$transport->getStream()->getDebug(); This provides access to all necessary resources for debugging and logging. https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Mailer/SentMessage.php Important, once getDebug has been called to the stream, the parameter is emptied in the Object and is no longer available in a later call to the same function! function getDebug( bool $cleanUp = true );
$stream->getDebug(false); With the Symfony/Mailer 6.1, it is also possible to implement the DSN-Functionality. If this is given, then the class "EsmtpTransport" can be extended and the function implemented For example: MDN is much simpler: $headers = $message->getHeaders();
$headers->addMailboxHeader('Disposition-Notification-To',$var); |
The Mailer class is intentionally not returning the SentMessage object because this high-level API is meant to be compatible with async processing of the sending (when instantiating it with a Messenger Bus). |
Yes, this information is also only for users who have used SwiftMailer and the separate Mailer class. Here I would refer to @Warxcell's post. |
@Orgoth even if you use the mailer standalone, I would still encourage to wire an event dispatcher (note that this does not require using the Symfony one as any PSR-14 implementation is supported). Several features (the Twig integration for TemplatedEmail for instead) rely on those events as those features are implemented as listeners. |
@stof The Mailer is used in an old project where are not Events, Listeners and so on. PSR-14 is nonexistence there.
But since this project is nearly 20 years old and i am only the small sending part, it will take some time. :) In all other cases, where the effort is manageable, PSR-14 should be used as recommended by you, in order to use the full potential. |
@stof I noticed this. But since we're not using Symfony framework or the event system, implementing support for that seemed overkill and not worth it. Maybe the event system is decent, I spent some time looking into it. But, for now we're sticking with our current event system that dispatches events to another node for processing (can support message queues). Subscribing to events is an interesting concept, one I haven't used extensively. But, it seems like it'd invite a whole mess of interwoven dependencies and reliance. Whereas dispatching events to another node that can process them off in a more predictable fashion has far less side-effects. It also comes with the benefit of knowing/debugging exactly what those side effects are for each event. I don't know - maybe I'm missing the ah ha. |
Thank you for this suggestion. |
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
…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
Add advanced debug logger. Just like in Doctrine you can see every single SQL sent to server, it would be useful to be able to see same for mailer. Currently the only option to read it to override the MessageHandler (when used in conjunction with Messenger)
Example
The text was updated successfully, but these errors were encountered: