-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] add reject to MessageEvent
to stop sending mail
#48409
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
Conversation
MessageEvent
to stop sending mail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do the same in Mailer to avoid sending an email on the queue if we don't want to send it.
Also, can you some tests?
MessageEvent
to stop sending mailMessageEvent
to stop sending mail
MessageEvent
to stop sending mailMessageEvent
to stop sending mail
Hi @y4roc, do you have time to handle the request change ? I'm really interested by this feature. :) |
@VincentLanglet Feel free to take over if you have time to finish this PR. |
Hi @fabpot, sure I'll be happy to do it. I think your review (#48409 (comment)) is incorrect, since the method need to return a
after the line
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to add some tests
You're right, so we are only missing some tests. |
@VincentLanglet I'm going to take over. |
Should rejecting the mail stop the propagation of the |
That's a good question. My take here is that you might have another listener interested in knowing the fact that the email has been rejected. It looks more flexible that way. |
Right, but that listener would need to operate on a lower priority than any listener that might potentially reject messages. 🤔 Does rejecting the mail trigger a
|
I would not trigger a As you don't necessarily know all listeners that can be registered in advance, maybe stopping the propagation is the more flexible way after all :) I've added another commit for that change. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
One last question: I think, a rejected message should appear in the logs. Right now, it would be the responsibility of the listener to do that, right? Since the listener should know best why it rejected a message, that's probably the best place to write this kind of log entry.
Should the Mailer
add a generic log entry about the rejection, maybe on debug level, to make the rejection discoverable in case the rejecting listener "forgets" to do so?
src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php
Outdated
Show resolved
Hide resolved
I would let the listener do the logging when it makes sense. I tend to avoid logging whenever possible. |
Thank you @y4roc. |
Add
reject()
inMessageEvent
to reject sending mail