[gsoc-admin] MailTemplate: Add sending ability
- From: Lasse Schuirmann <lschuirma src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gsoc-admin] MailTemplate: Add sending ability
- Date: Wed, 12 Aug 2015 10:28:22 +0000 (UTC)
commit cb1639cd4bc9eea68825efb7419dc8a8282aae0a
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date: Wed Aug 12 12:28:06 2015 +0200
MailTemplate: Add sending ability
email/email.py | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/email/email.py b/email/email.py
index 2528470..ca9e1d3 100755
--- a/email/email.py
+++ b/email/email.py
@@ -1,6 +1,23 @@
#!/usr/bin/env python3
+def send_mail(text, recipient):
+ raise NotImplementedError
+
+
+class Recipient:
+ def __init__(self, mail, name=None):
+ self.mail = mail
+ self._name = name
+
+ @property
+ def name(self):
+ return self.name or "Unknown Name"
+
+ def __str__(self):
+ return "{name} <{mail}>".format(name=self.name, mail=self.mail)
+
+
class EmailTemplate:
def __init__(self, text, recipients):
self.text = text
@@ -9,6 +26,12 @@ class EmailTemplate:
def get_specific(self, data_dict):
return self.text.format(**data_dict)
+ def send(self, data_dict):
+ data_dict = data_dict.copy()
+ for recipient in self.recipients:
+ data_dict['recipient_name'] = recipient.name
+ send_mail(self.get_specific(data_dict), str(recipient))
+
template_file = open('../data/templates/foo')
template_text = template_file.read()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]