diff options
| author | Alon Levy <alon@pobox.com> | 2015-01-13 08:36:01 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-01-13 10:24:00 +0200 |
| commit | eced38bfff26a9c7faf78683fe15f148732cd9cf (patch) | |
| tree | 452466fa7c2923702df73fd2546da94b149d9925 /src/server/rz_mail.py | |
| parent | 96534de0c0dceefde8795e879927c5bedbdaa858 (diff) | |
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
Diffstat (limited to 'src/server/rz_mail.py')
| -rw-r--r-- | src/server/rz_mail.py | 27 |
1 files changed, 27 insertions, 0 deletions
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) + |
