Add basic support for email attachments.
This is hopefully at least somewhat proper...
This commit is contained in:
parent
cd93b6b247
commit
9af88bf4cc
|
@ -31,6 +31,8 @@ import smtplib
|
|||
import warnings
|
||||
import logging
|
||||
from email.message import Message
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
|
||||
|
@ -196,8 +198,16 @@ def make_message_config(config, key, body, subject=None, recipients=None, attach
|
|||
foo.bcc =
|
||||
admin@example.com
|
||||
"""
|
||||
message = Message()
|
||||
message.set_type('text/html')
|
||||
if attachments is not None:
|
||||
message = MIMEMultipart()
|
||||
message.attach(MIMEText(body))
|
||||
for attachment in attachments:
|
||||
message.attach(attachment)
|
||||
else:
|
||||
message = Message()
|
||||
message.set_payload(body, 'utf_8')
|
||||
message.set_type('text/html')
|
||||
|
||||
message['From'] = get_sender(config, key)
|
||||
if recipients is None:
|
||||
recipients = get_recipients(config, key)
|
||||
|
@ -206,7 +216,6 @@ def make_message_config(config, key, body, subject=None, recipients=None, attach
|
|||
if subject is None:
|
||||
subject = get_subject(config, key)
|
||||
message['Subject'] = subject
|
||||
message.set_payload(body, 'utf_8')
|
||||
return message
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue