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

[11.x] Allow view content dependent mail callbacks #51990

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

MaxTingle
Copy link
Contributor

@MaxTingle MaxTingle commented Jul 2, 2024

Since the swap from SwiftMailer to Symfony Mailer DKIM has been difficult to work with as per this discussion.

Symfony's signing has only been able to execute after Message generation, but requires content for its signature generation which is only set after its execution, throwing A message must have a text or an HTML part or attachments. when it's missing.

By executing the callback after content generation we allow DKIM signing to use it and succeed, for example:

$mailable->withSymfonyMessage(function (Email $message): void {
    $dkimSigner = new DkimSigner('private', 'domain', 'selector');
    $dkimSigner->sign($message);
});

@taylorotwell
Copy link
Member

taylorotwell commented Jul 3, 2024

I have a pretty strong fear that changing the order of when this is done in relation to the invocation of this callback could break existing applications. We may need another way to solve this problem?

@taylorotwell taylorotwell reopened this Jul 3, 2024
@MaxTingle
Copy link
Contributor Author

@taylorotwell addContent sets the Email instance html, html charset, text and text charset while rendering the view if one is used, but it does this using the values passed in from Mailable so currently:

  • Calls to html/text on the Symfony Email passed into Illuminate Mailable->withSymfonyMessage callbacks are immediately overridden by Illuminate Mailer->addContent running after the callbacks, with the Mailable's html/text/view replacing any content directly set on the Email
  • Calls to html/text/view on the Illuminate Mailable during a withSymfonyMessage callback have no affect, as the Mailable has already called Mailable->buildView and Mailable->buildViewData during the Illuminate Mailer->send it does from Mailable->send, so the values Mailer->addContent uses are not changed

This means the change is only breaking if you intended to change the html/text of a Symfony Email in Mailable->withSymfonyMessage, as previously it would do nothing and now it would override the Mailable html/text/view already set on the Email

Other than this I cannot foresee any breakages to existing applications, can you think of any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants