mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Fixes email sending.
Now works with HTML + alternative plain text + attachments.
This commit is contained in:
parent
cfd9543d92
commit
1cbdc56969
1 changed files with 6 additions and 4 deletions
|
@ -13,10 +13,7 @@ def send(to, subject, body, html=None, copy=None, attachments=None):
|
||||||
if not attachments:
|
if not attachments:
|
||||||
attachments = []
|
attachments = []
|
||||||
|
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart('alternative')
|
||||||
msg.attach(MIMEText(body, "plain"))
|
|
||||||
if html:
|
|
||||||
msg.attach(MIMEText(html, "html"))
|
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
msg["From"] = config.FROM_EMAIL
|
msg["From"] = config.FROM_EMAIL
|
||||||
msg["To"] = to
|
msg["To"] = to
|
||||||
|
@ -30,6 +27,11 @@ def send(to, subject, body, html=None, copy=None, attachments=None):
|
||||||
filename=file_name)
|
filename=file_name)
|
||||||
encoders.encode_base64(part)
|
encoders.encode_base64(part)
|
||||||
msg.attach(part)
|
msg.attach(part)
|
||||||
|
|
||||||
|
msg.attach(MIMEText(body, "plain"))
|
||||||
|
if html:
|
||||||
|
msg.attach(MIMEText(html, "html"))
|
||||||
|
|
||||||
if not config.SEND_EMAILS:
|
if not config.SEND_EMAILS:
|
||||||
return print("Sending email", str(body))
|
return print("Sending email", str(body))
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue