diff options
author | Magnus Hagander | 2013-07-19 12:55:56 +0000 |
---|---|---|
committer | Magnus Hagander | 2013-07-19 12:55:56 +0000 |
commit | 3a0dcbdbff5d1dbdef75eee000075c67c27f2915 (patch) | |
tree | 99cab09d9038dcd5ff72522771005144a151972e /pgcommitfest/mailqueue/util.py |
Really need to get this into git, so I can do some hacking.
May very well do a complete rebase later to get rid of history
Diffstat (limited to 'pgcommitfest/mailqueue/util.py')
-rw-r--r-- | pgcommitfest/mailqueue/util.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pgcommitfest/mailqueue/util.py b/pgcommitfest/mailqueue/util.py new file mode 100644 index 0000000..6e59411 --- /dev/null +++ b/pgcommitfest/mailqueue/util.py @@ -0,0 +1,34 @@ +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from email.mime.nonmultipart import MIMENonMultipart +from email.Utils import formatdate + +from models import QueuedMail + +def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None): + # attachment format, each is a tuple of (name, mimetype,contents) + # content should already be base64 encoded + msg = MIMEMultipart() + msg['Subject'] = subject + msg['To'] = receiver + msg['From'] = sender + msg['Date'] = formatdate(localtime=True) + + msg.attach(MIMEText(msgtxt, _charset='utf-8')) + + if attachments: + for filename, contenttype, content in attachments: + main,sub = contenttype.split('/') + part = MIMENonMultipart(main,sub) + part.set_payload(content) + part.add_header('Content-Transfer-Encoding', 'base64') + part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename) + msg.attach(part) + + + # Just write it to the queue, so it will be transactionally rolled back + QueuedMail(sender=sender, receiver=receiver, fullmsg=msg.as_string()).save() + +def send_mail(sender, receiver, fullmsg): + # Send an email, prepared as the full MIME encoded mail already + QueuedMail(sender=sender, receiver=receiver, fullmsg=fullmsg).save() |