1 |
commit: 78c83d8030ad8628887e2705bdc95b485a8e42be |
2 |
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com> |
3 |
AuthorDate: Sat Aug 27 14:07:07 2016 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Dec 24 04:54:14 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=78c83d80 |
7 |
|
8 |
Added a mail script that handles the emailing proccess |
9 |
|
10 |
I created a new file called `mail.py` that handles the email login and the email sending. |
11 |
|
12 |
gkeys/gkeys/mail.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 |
1 file changed, 51 insertions(+) |
14 |
|
15 |
diff --git a/gkeys/gkeys/mail.py b/gkeys/gkeys/mail.py |
16 |
new file mode 100644 |
17 |
index 0000000..df86d11 |
18 |
--- /dev/null |
19 |
+++ b/gkeys/gkeys/mail.py |
20 |
@@ -0,0 +1,51 @@ |
21 |
+from __future__ import print_function |
22 |
+ |
23 |
+import os |
24 |
+import smtplib |
25 |
+import sys |
26 |
+import email.utils |
27 |
+ |
28 |
+from email.mime.text import MIMEText |
29 |
+from snakeoil.demandload import demandload |
30 |
+ |
31 |
+if sys.version_info[0] >= 3: |
32 |
+ py_input = input |
33 |
+ _unicode = str |
34 |
+else: |
35 |
+ py_input = raw_input |
36 |
+ _unicode = unicode |
37 |
+ |
38 |
+demandload( |
39 |
+ "gkeys.base:Args", |
40 |
+ "json:load", |
41 |
+) |
42 |
+ |
43 |
+class Emailer(object): |
44 |
+ '''Send an email reminder about the status of the user's GPG key''' |
45 |
+ |
46 |
+ def __init__(self, login, logger): |
47 |
+ self.logger = logger |
48 |
+ self.email_from = _unicode(login['login_email']) |
49 |
+ self.sender_full_name = _unicode(login['full_name']) |
50 |
+ login_passwd = login['passwd'] |
51 |
+ server = login['server'] |
52 |
+ self.mail = smtplib.SMTP(server, 587) |
53 |
+ self.mail.ehlo() |
54 |
+ self.mail.starttls() |
55 |
+ self.mail.login(self.email_from, login_passwd) |
56 |
+ self.logger.debug(_unicode("Login successfull")) |
57 |
+ |
58 |
+ def send_email(self, uid, message): |
59 |
+ self.logger.debug(_unicode('Sending email with message %s') % _unicode(message)) |
60 |
+ subject = "Expiring Key" |
61 |
+ email_to = uid |
62 |
+ msg = MIMEText(message, 'plain') |
63 |
+ msg['Subject'] = subject |
64 |
+ msg['From'] = email.utils.formataddr((self.sender_full_name, self.email_from)) |
65 |
+ msg['To'] = email_to |
66 |
+ self.logger.info(_unicode('Sending the email reminder from %s to %s') \ |
67 |
+ % (self.email_from, email_to)) |
68 |
+ self.mail.sendmail(self.email_from, email_to, msg.as_string()) |
69 |
+ |
70 |
+ def email_quit(self): |
71 |
+ self.mail.quit() |