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

Adjusted TransportBuilder prepareMessage method to support text/plain… #26474

Merged
merged 1 commit into from
May 14, 2020

Conversation

twoonesixdigital
Copy link

@twoonesixdigital twoonesixdigital commented Jan 21, 2020

Description (*)

As of 2.3.3, Magento's Magento\Framework\Mail\Template\TransportBuilder class can no longer send emails whose "Content-Type" header is set to "text/plain". This is because the TransportBuilder's prepareMessage method does not pass the determined template type to the mimePartInterfaceFactory's create method. When no "type" key is present in the array passed to the create method, the mimePartInterfaceFactory defaults to "text/html".

This pull request simply modifies the prepareMessage method so that it passes the previously determined template type to the mimePartInterfaceFactory's create method.

Fixed Issues (if relevant)

  1. Fixed TransportBuilder unable to send emails of Content-Type "text/plain" as of 2.3.3 #26471: TransportBuilder unable to send emails of Content-Type "text/plain" as of 2.3.3

Manual testing scenarios (*)

  1. Define an email template of type "text" via an email_templates.xml file
  2. Attempt to use the TransportBuilder's sendMessage() method to send an email based on that template:
$transport = $this->TransportBuilder->setTemplateIdentifier('some_template_id')
	->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
	->setFrom("email@domain.com")
	->addTo("email@domain.com")
	->getTransport()
	->sendMessage();

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jan 21, 2020

Hi @twoonesixdigital. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

$mimePart = $this->mimePartInterfaceFactory->create(
[
'content' => $content,
'type' => $part['type']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the variable name is not coming from you but it looks like that $part is never defined as an array prior. Since it only uses type maybe it makes sense to rename $part['type'] to $partType?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree. I suspect usage of the $part array is probably an artifact of an older version of the class. Replacing that with something simpler and less ambiguous would likely reduce confusion.

@thiaramus
Copy link
Contributor

The internal Magento team is working on this issue right now.
The fix will be based on commits from the author and delivered according to our internal processes. All original commits made by the author will be preserved.

@slavvka slavvka merged commit 380ca84 into magento:2.4-develop May 14, 2020
@m2-assistant
Copy link

m2-assistant bot commented May 14, 2020

Hi @twoonesixdigital, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ghost ghost moved this from Pending Review to Recently Merged in Pull Requests Dashboard May 14, 2020
@magento-engcom-team magento-engcom-team removed this from Recently Merged in Pull Requests Dashboard May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TransportBuilder unable to send emails of Content-Type "text/plain" as of 2.3.3
5 participants