From c8cbf8cc0e4680852bc64fbb77f31be3bb2a2dbd Mon Sep 17 00:00:00 2001 From: ryv-odoo Date: Fri, 11 Oct 2019 10:03:38 +0000 Subject: [PATCH] [FIX] base, mail: fix multipart alternative order After the refactor of mail sending with the newest python API (18299d7e5051cdad29854bc7280db5002a209500), the order of multipart/alternative was wrong for email. Indeed, in the MIME protocol [1], for The Multipart/alternative subtype the order is significant: "In general, user agents that compose multipart/alternative entities should place the body parts in increasing order of preference, that is, with the preferred format last". This bug caused some issues with mail marketing (see related task) with Gmail web client (see the plaintext instead of html mail). The fix is to inverse the order of adding alternative in the mail content. [1] https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html TASK_ID : 2084989 closes odoo/odoo#38490 Signed-off-by: Thibault Delavallee (tde) --- odoo/addons/base/models/ir_mail_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/ir_mail_server.py b/odoo/addons/base/models/ir_mail_server.py index 8858fd3602c..e735c871708 100644 --- a/odoo/addons/base/models/ir_mail_server.py +++ b/odoo/addons/base/models/ir_mail_server.py @@ -283,11 +283,11 @@ class IrMailServer(models.Model): email_body = ustr(body) if subtype == 'html' and not body_alternative: - msg.add_alternative(email_body, subtype=subtype, charset='utf-8') msg.add_alternative(html2text.html2text(email_body), subtype='plain', charset='utf-8') - elif body_alternative: msg.add_alternative(email_body, subtype=subtype, charset='utf-8') + elif body_alternative: msg.add_alternative(ustr(body_alternative), subtype=subtype_alternative, charset='utf-8') + msg.add_alternative(email_body, subtype=subtype, charset='utf-8') else: msg.set_content(email_body, subtype=subtype, charset='utf-8')