magento2,email,css,email-templates,order-email – Fixing CSS Minification Breaking Email CSS in Magento 2

cssemailemail-templatesmagento2order-email

Some of the css in email is broken after I enabled minification of css. I assume the reason being this :

email.css and email-inline.css are called from email header i.e header.html

But when I enable minification and deploy content, I dont see email.css and email-inline.css files instead I see their minified version as email.min.css and email-inline.min.css respectively.

So I tried to resolve the issue by renaming the calling in header.html.
It dint help.

Then I copied the minifiled files and renamed them to .css files
That also dint help.

What do u think might be the issue ?

UPDATE:

I have used inline css overall the email template. The css is broken for the Order Details in Order Confirmation email, return email etc.
The Order Details comes from an xml internally calling a phtml file.

{{layout handle="sales_email_order_items" order=$order area="frontend"}}

Internally it calls items.phtml. I can not add inline css to this phtml file as this file is being used in frontend as well on order view page where the item details are rendered.
How Can I take care of these sections in emails so that the css is not broken?

Email without minified css:

enter image description here

Email with minified css(broken css)

enter image description here

UPDATE:

I have now added css in the header.html in style tag and removed call to email-inline.css and email.css. When I view the email in outlook or gmail the css is still broken. However If I open the mail in browser(View in browser) the section looks fine.

Best Answer

As Sejal said, the recommended way is to use Magento 2 less files which is processed by Emogrifier.

The problem is that Magento 2 did not upgrade this library in composer.

I faced on this issue too and found a workaround :

Update your root composer.json and add this require line :

"pelago/emogrifier": "1.2.0 as 0.1.1"

Then do a composer update and your mail css should be working.

Moreover, I faced on this issue when I set production mode and not developer mode which enabled minification by default.

Latest Emogrifier release : https://github.com/jjriv/emogrifier/releases

Related Topic