Skip to content

Comments

#3293 feat: add mail exception event#5243

Open
pquerner wants to merge 6 commits intoOpenMage:mainfrom
pquerner:feature/3293_mail-exception-event
Open

#3293 feat: add mail exception event#5243
pquerner wants to merge 6 commits intoOpenMage:mainfrom
pquerner:feature/3293_mail-exception-event

Conversation

@pquerner
Copy link
Contributor

@pquerner pquerner commented Jan 22, 2026

Description (*)

This PR adds a new event email_exception around email sending code. In this event one can check for errors or do logging. Normally the exceptions are caught by Mage::logException which then does not give all needed context data to make a deeper analysis.

Fixed Issues (if relevant)

Manual testing scenarios (*)

  1. Manually patch \Zend_Mail_Transport_Sendmail::_sendMail to always throw a exception
    (could not find a way to do it by misconfiguration or otherwise)
  2. Trigger exception by adding debug code to a place of your convenience:
try {
            $mailer = Mage::getModel('core/email')
                ->setType('plain')
                ->setToName("max")
                ->setBody('foo')
                ->setToEmail("max@example.com")
                ->send();
        } catch (Exception $e) {
            $f = 1;
        }

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_exception event 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

@loekvangool
Copy link
Contributor

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.

@pquerner
Copy link
Contributor Author

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.

@pquerner pquerner force-pushed the feature/3293_mail-exception-event branch from bf22c72 to a207857 Compare February 15, 2026 21:45
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Core Relates to Mage_Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants