From eced38bfff26a9c7faf78683fe15f148732cd9cf Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 13 Jan 2015 08:36:01 +0200 Subject: incorporate https://github.com/ivoviz/feedback allows user to mark an image and send it. sends an email to configured recipient. defaults to using localhost:25 as the SMTP server (no user name, no password, see [1] for configuration parameters of flask-mail). Introduces a config parameter: FEEDBACK_RECIPIENT = feedback@localhost left TODO: 1. customize the 'thank you' text 2. document in user guide (setting MAIL_DEFAULT_SENDER correctly) [1] https://pythonhosted.org/Flask-Mail/#configuring-flask-mail --- src/server/rz_mail.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/server/rz_mail.py (limited to 'src/server/rz_mail.py') diff --git a/src/server/rz_mail.py b/src/server/rz_mail.py new file mode 100644 index 00000000..0ecf1d61 --- /dev/null +++ b/src/server/rz_mail.py @@ -0,0 +1,27 @@ +import magic + +from flask_mail import Mail, Message + +mail = None + +magic_mime = magic.open(magic.MAGIC_MIME) +magic_mime.load() + +def mimetype(data): + return magic_mime.buffer(data).split(';')[0] + +def init_mail(webapp): + global mail + mail = Mail(webapp) + +def send_message(recipients, subject, attachments, body): + """ + attachments is a list of tuples (filename, data) + libmagic is used to guess the mimetype + """ + msg = Message(subject, recipients=recipients) + msg.body = body + for filename, data in attachments: + msg.attach(filename=filename, content_type=mimetype(data), data=data) + mail.send(msg) + -- cgit v1.3.1