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

MailProcessor adds Recipient twice #2581

Open
solverat opened this issue Mar 12, 2024 · 4 comments
Open

MailProcessor adds Recipient twice #2581

solverat opened this issue Mar 12, 2024 · 4 comments

Comments

@solverat
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
  • Create a Mail Template
  • Add "[email protected]" in To: field
  • Use notification rule or just use $this->mailProcessor->sendMail($mailDocument, $order, null, [], $mailParams);
  • Mail gets submitted twice

Reason:

$storedRecipients = array_filter(explode(';', $document->getTo()));
foreach ($storedRecipients as $multiRecipient) {
$toRecipients[] = [$multiRecipient, ''];
}
}
foreach ($toRecipients as $recipient) {
$this->addTo($recipient[0], $recipient[1]);
}

Which is just a duplicate of pimcores internal mail processor:

https://github.com/pimcore/pimcore/blob/3b9af529ec41cc6a9723dde96714df67b65d6078/lib/Mail.php#L378-L382

@dpfaffenbauer
Copy link
Member

where does pimcore add the to again?

@solverat
Copy link
Contributor Author

@dpfaffenbauer: Pimcore doesn't, CoreShop does. Because coreshop uses the $mail->setDocument(), pimcore internally calls setDocumentSettings() which applies all recipients.

After that, coreshop also adds them here:

$storedRecipients = array_filter(explode(';', $document->getTo()));
foreach ($storedRecipients as $multiRecipient) {
$toRecipients[] = [$multiRecipient, ''];
}
}
foreach ($toRecipients as $recipient) {
$this->addTo($recipient[0], $recipient[1]);
}

Most of the time, shop mails property $to is empty, because they should be dynamically sent to the customer. But using notification rules with a defined recipient, the mail will be submitted twice.

@dpfaffenbauer
Copy link
Member

So we should stop adding that then right? or at least check for duplicates?

@solverat
Copy link
Contributor Author

Removing this part should be safe, I guess?

if ($document instanceof Email) {
//now add recipients from emailDocument, if given.
$storedRecipients = array_filter(explode(';', $document->getTo()));
foreach ($storedRecipients as $multiRecipient) {
$toRecipients[] = [$multiRecipient, ''];
}
}

This part is covered in MailProcessor->setDocument() which triggers the setDocumentSettings() method.

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

No branches or pull requests

2 participants