diff options
| author | Alon Levy <alon@pobox.com> | 2015-01-13 20:32:33 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-01-13 20:32:33 +0200 |
| commit | 1bb9bd552b5c8c7142a6d4aff329e00b2682ceb7 (patch) | |
| tree | d3a06fd5af37f498390bec07e3dd2eee933fd877 /src | |
| parent | 8f88d7d7618d52bfeae5b9a51c06a5b91b545a71 (diff) | |
server: fix rz_mail: Fixes #274; Fixes #273
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/rz_mail.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/server/rz_mail.py b/src/server/rz_mail.py index 4addc9f2..1d93321b 100644 --- a/src/server/rz_mail.py +++ b/src/server/rz_mail.py @@ -9,17 +9,25 @@ from email import Encoders from flask import current_app def send_message(recipients, subject, attachments, body): + send_from = current_app.rz_config.mail_default_sender + smtp_hostname = current_app.rz_config.mail_hostname + send_message_helper(smtp_hostname=smtp_hostname, + send_from=send_from, recipients=recipients, + subject=subject, attachments=attachments, body=body) + +def send_message_helper(smtp_hostname, send_from, recipients, subject, attachments, body): """ attachments is a list of tuples (filename, mimetype, data) + + note: helper exists for ease of testing, since it doesn't use flask only + python batteries-included packages """ assert isinstance(recipients, list) - send_from = current_app.rz_config.mail_default_sender - msg = MIMEMultipart( - From=send_from, - To=COMMASPACE.join(recipients), - Date=formatdate(localtime=True), - Subject=subject - ) + msg = MIMEMultipart() + msg['From'] = send_from + msg['To'] = COMMASPACE.join(recipients) + msg['Date'] = formatdate(localtime=True) + msg['Subject'] = subject msg.attach(MIMEText(body)) for filename, mimetype, data in attachments: @@ -27,9 +35,15 @@ def send_message(recipients, subject, attachments, body): part = MIMEBase(maintype, subtype) part.set_payload(data) Encoders.encode_base64(part) - part.add_header('Content_Disposition', 'attachment; filename="%s"' % filename) + part.add_header('Content-Disposition', 'attachment', filename=filename) + #Content_Disposition: attachment; filename="feedback_page.html" msg.attach(part) - smtp = smtplib.SMTP(current_app.rz_config.mail_hostname) + smtp = smtplib.SMTP(smtp_hostname) smtp.sendmail(send_from, recipients, msg.as_string()) smtp.close() + +if __name__ == '__main__': + # FIXME - move to actual test suite + send_message_helper('localhost', 'alon@localhost', ['alon@localhost'], 'test subject', [ + ('diary.txt', 'text/plain', "bla bla bla yeah that's right bla")], 'this is it pal') |
