Skip to content

Commit efd91e0

Browse files
committed
rex.sendmail: fix for duplicate Content-Type in html messages
1 parent ae31a06 commit efd91e0

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/rex.sendmail/src/rex/sendmail.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def compose(template_path, html_template_path=None, **arguments):
8888
jinja = get_jinja()
8989
text = jinja.get_template(template_path).render(**arguments)
9090
text_message = email.message_from_string(text)
91+
msg_headers = list(text_message.items())
9192
body_text = text_message.get_payload()
9293
text_message.set_charset('utf-8')
9394

@@ -125,8 +126,9 @@ def compose(template_path, html_template_path=None, **arguments):
125126

126127
# Redefine message as alternative with html and tect attachments
127128
message = email.mime.multipart.MIMEMultipart('alternative')
128-
for k, v in text_message.items():
129+
for k, v in msg_headers:
129130
message[k] = v
131+
del text_message[k]
130132
message.attach(text_message)
131133
message.attach(html_message) # the last attachment is preferred
132134

src/rex.sendmail/test/test_sendmail.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,8 @@ src="cid:path" >``::
131131
From: Alice Anderson <[email protected]>
132132
To: Bob Brown <[email protected]>
133133
Subject: Hi there!
134-
MIME-Version: 1.0
135-
Content-Type: multipart/alternative; boundary="..."
136-
Content-Transfer-Encoding: base64
137134
STRUCTURE:
138-
type=multipart/alternative, disposition=None, encoding=base64, id=None
135+
type=multipart/alternative, disposition=None, encoding=None, id=None
139136
type=text/plain, disposition=None, encoding=base64, id=None
140137
type=multipart/related, disposition=None, encoding=None, id=None
141138
type=text/html, disposition=None, encoding=7bit, id=None

0 commit comments

Comments
 (0)