Closed
Description
Preconditions (*)
- Magento Community Edition 2.3.3
- One or more Magento email templates configured as type "text" via an email_templates.xml file.
Steps to reproduce (*)
1.Attempt to send a template based email of type "text" using Magento\Framework\Mail\Template\TransportBuilder that is of Content-Type "text/plain" using the TransportBuilder class's sendMessage method.
Expected result (*)
- An email is dispatched whose "Content-Type" header is set to "text/plain"
Actual result (*)
- The email is sent with a "Content-Type" header set to "text/html"
Additional Information (*)
It appears that as of Magento 2.3.3, it is no longer possible to send "text/plain" emails using the TransportBuilder. This is because, as of 2.3.3, the TransportBuilder's prepareMessage method does not pass the determined template type to the mimePartInterfaceFactory's create method.
Current method definition as of 2.3.3:
protected function prepareMessage()
{
$template = $this->getTemplate();
$content = $template->processTemplate();
switch ($template->getType()) {
case TemplateTypesInterface::TYPE_TEXT:
$part['type'] = MimeInterface::TYPE_TEXT;
break;
case TemplateTypesInterface::TYPE_HTML:
$part['type'] = MimeInterface::TYPE_HTML;
break;
default:
throw new LocalizedException(
new Phrase('Unknown template type')
);
}
$mimePart = $this->mimePartInterfaceFactory->create(['content' => $content]);
$this->messageData['body'] = $this->mimeMessageInterfaceFactory->create(
['parts' => [$mimePart]]
);
$this->messageData['subject'] = html_entity_decode(
(string)$template->getSubject(),
ENT_QUOTES
);
$this->message = $this->emailMessageInterfaceFactory->create($this->messageData);
return $this;
}
Proposed change that would resolve issue (only the relevant snippet):
$mimePart = $this->mimePartInterfaceFactory->create(
[
'content' => $content,
'type' => $part['type']
]
);
(Pull request incoming)