#3293 feat: add mail exception event#5243
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new email_exception event to improve debugging capabilities for email sending failures. The event provides additional context (template object, mail object, exception, and other relevant data) that is not available through the standard Mage::logException call.
Changes:
- Added try-catch blocks and
email_exceptionevent dispatching in three email-related classes - The event allows observers to capture and analyze email failures with full context
- Different exception handling approaches: Template.php and Queue.php catch and suppress, Email.php catches and re-throws
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/code/core/Mage/Core/Model/Email/Template.php | Adds email_exception event in catch block with template context data |
| app/code/core/Mage/Core/Model/Email/Queue.php | Adds email_exception event in catch block with queue message context data |
| app/code/core/Mage/Core/Model/Email.php | Wraps email sending in try-catch, dispatches email_exception event, and re-throws exception |
|
I wonder if we should improve the quality of the log message as well, while we're adding the ability for people to listen to the event. |
|
I could see this in a followup PR, example: Add observer to new events, behind a yes/no system config to allow logs and if so it what file (name). I like PRs as small as possible to (limit only to the needed scope) for quick review phase, if possible. |
bf22c72 to
a207857
Compare
|



Description (*)
This PR adds a new event
email_exceptionaround email sending code. In this event one can check for errors or do logging. Normally the exceptions are caught byMage::logExceptionwhich then does not give all needed context data to make a deeper analysis.Fixed Issues (if relevant)
Manual testing scenarios (*)
\Zend_Mail_Transport_Sendmail::_sendMailto always throw a exception(could not find a way to do it by misconfiguration or otherwise)
Contribution checklist (*)