Skip to content
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

Improve support for Email Failure messages #3443

Closed
BenParizek opened this issue Nov 6, 2018 · 2 comments
Closed

Improve support for Email Failure messages #3443

BenParizek opened this issue Nov 6, 2018 · 2 comments
Labels
enhancement improvements to existing features extensibility 🔌 features related to plugin/module dev

Comments

@BenParizek
Copy link
Contributor

BenParizek commented Nov 6, 2018

We have a plugin that tracks Sent Emails and attempts to share details with the user about why an email was successful or why it failed. In Craft 2, we had the onSendEmailError event to help out with this info.

In Craft 3, there seem to be several points of failure for email and we're having a hard time getting the specific error message back in many cases. We're currently watching the Yii BaseMailer::EVENT_AFTER_SEND event which does appear to return an error message in place of the $message and provide an $isSuccessful flag:

$event = new MailEvent(['message' => $message, 'isSuccessful' => $isSuccessful]);

However, Craft seems to intercept that response with its own try/catch blocks in different contexts and in several cases we seem to never have a chance to get that response from the Message class back.

If Craft finds a TemplateLoaderException, it throws it before the Mailer has a chance to throw an error:
https://github.com/craftcms/cms/blob/develop/src/mail/Mailer.php#L144

Craft also throws a different error if it finds a Swift_TransportException error:
https://github.com/craftcms/cms/blob/develop/src/mail/Mailer.php#L177

In the case of the TemplateLoaderException Craft throws an error. In the case of the Swift_TransportException it just returns false.

I'm not sure what the best solution here would be but it would be nice if we could either:

  1. Have all email errors returned in a consistent way so BaseMailer::EVENT_AFTER_SEND returns predictable results when any error is encountered
  2. Have Craft add it's own EVENT_AFTER_SEND on the craft\mail\Mailer class and refactor any errors to be returned in a consistent way
  3. Have Craft provide additional events to watch for any potential errors such as specific events for Template or Transport email errors
@brandonkelly brandonkelly added enhancement improvements to existing features extensibility 🔌 features related to plugin/module dev labels Nov 6, 2018
brandonkelly added a commit that referenced this issue Jan 10, 2019
@brandonkelly
Copy link
Member

Just addressed this for the next 3.1 release.

@BenParizek
Copy link
Contributor Author

Thanks! We'll check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features extensibility 🔌 features related to plugin/module dev
Projects
None yet
Development

No branches or pull requests

2 participants