Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
choose between html and text
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed May 3, 2016
1 parent b59e7b1 commit 7e4768d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pymmails/sender/email_sender.py
Expand Up @@ -30,6 +30,7 @@ def compose_email(fr, to, subject, body_html=None, body_text=None, attachements=
@return string
If the file is a text file, the filename can be replaced by (filename, encoding).
If *body_html* and *body_text* are filled, only the first one will be used.
"""
if isinstance(to, str):
to = [to]
Expand All @@ -44,12 +45,15 @@ def compose_email(fr, to, subject, body_html=None, body_text=None, attachements=
outer['To'] = COMMASPACE.join(to)
outer['From'] = fr

if body_text is not None:
part1 = MIMEText(body_text, 'plain')
outer.attach(part1)
if body_html is not None:
part2 = MIMEText(body_html, 'html')
outer.attach(part2)
elif body_text is not None:
part1 = MIMEText(body_text, 'plain')
outer.attach(part1)
else:
# no body
pass

if cc is not None:
outer["Cc"] = ";".join(cc)
Expand Down

0 comments on commit 7e4768d

Please sign in to comment.