Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from Serializator/reuse-message-body
Browse files Browse the repository at this point in the history
Reuse the parts in the message body
  • Loading branch information
Mischa Braam authored Apr 8, 2020
2 parents 31c8f3a + 34b880f commit e41b2de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
23 changes: 2 additions & 21 deletions Mail/Template/TransportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,8 @@ protected function attachAttachmentsToBody()
// @see https://magento.stackexchange.com/questions/292760/unable-to-add-attachment-in-email-after-upgrade-to-magento-2-3-3-version

$mimeMessage = $this->mimeMessageFactory->create();
/** @var Part $bodyPart */
$bodyPart = $this->partFactory->create(['content' => $this->message->getBody()]);
// Cannot inherit through $this->message. Default is utf-8.
$bodyPart->setCharset('utf-8');

// Re-used from prepare message, can be removed in 2.3.3.
// Because they are using parts by default. These interface type logic can be removed.
$template = $this->getTemplate();
switch ($template->getType()) {
case TemplateTypesInterface::TYPE_TEXT:
$bodyPart->setType(Mime::TYPE_TEXT);
$mimeMessage->setParts(array_merge([$bodyPart], $this->attachments));
$this->message->setBodyText($mimeMessage);
break;

case TemplateTypesInterface::TYPE_HTML:
$bodyPart->setType(Mime::TYPE_HTML);
$mimeMessage->setParts(array_merge([$bodyPart], $this->attachments));
$this->message->setBodyHtml($mimeMessage);
break;
}
$mimeMessage->setParts(array_merge($this->message->getBody()->getParts(), $this->attachments));
$this->message->setBody($mimeMessage);
}
}

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
],
"license": "MIT",
"minimum-stability": "stable",
"require": {
"magento/framework": ">=102.0.0 <102.0.3"
},
"autoload": {
"psr-4": {
"WeProvide\\MailAttachment\\": ""
Expand Down

0 comments on commit e41b2de

Please sign in to comment.