verbb / comments

A Craft CMS plugin for managing comments directly within the CMS.
Other
137 stars 33 forks source link

Set the key to emails before they're being sent #282

Closed ryssbowh closed 8 months ago

ryssbowh commented 1 year ago

What are you trying to do?

Hi,

I created a plugin Email which basically overrides the system messages system to add some features : Project config integration, logging, resend, cc, bcc, translations etc

Some users are reporting a conflict with the Comments plugin when it sends out emails. Comments seems to create the email with Craft::createObject there without settings its key, which is what Mailer::composeFromKey() would do for example. So when the email is sent other plugins can't know what system message is being sent.

Would you be open to set the key on the emails before they're being sent ?

Original issue : https://github.com/ryssbowh/craft-emails/issues/10

Version affected : ^1.0 for sure and most likely ^2.0 according to what I see there

What's your proposed solution?

Use Mailer::composeFromKey() to create emails, or set the key to the email manually

Additional context

No response

engram-design commented 1 year ago

This is because we custom-render the email content, rather than rely on Mailer::composeFromKey which provides quick and simple mail handling, but is not as flexible. Especially if we want access to the message object, which in our case we add Markdown support for the mail, and customer-provided templates.

I've modified this line to be:

$message = $mailer->composeFromKey($key, $variables);

But not seeing any change in behaviour. I've also tried:

$message = Craft::createObject(['class' => $mailer->messageClass, 'mailer' => $mailer, 'key' => $key, 'variables' => $variables]);

Which is essentially the same thing, but the same resulting error.

Are these working on your end?

ryssbowh commented 1 year ago

Ha I didn't realise you were the dev there.

Thanks for that, Yes it works for me with your second solution and Emails 1.4.7. I only tried the second solution but it would work as long as the key is set to the email object.

engram-design commented 1 year ago

Right, I need to re-install the plugin (either one) to get that to work, along with 1.4.8 of your plugin.

Fixed for the next release. To get this early run composer require verbb/comments:"dev-craft-3 as 1.9.5"

engram-design commented 8 months ago

Fixed in 1.9.6