summaryrefslogtreecommitdiff
path: root/emailcanary/email-digest-sender.py
diff options
context:
space:
mode:
Diffstat (limited to 'emailcanary/email-digest-sender.py')
-rw-r--r--emailcanary/email-digest-sender.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/emailcanary/email-digest-sender.py b/emailcanary/email-digest-sender.py
new file mode 100644
index 0000000..f1583c0
--- /dev/null
+++ b/emailcanary/email-digest-sender.py
@@ -0,0 +1,38 @@
+import emailutils
+import smtplib
+from email import message
+
+PASSWORD="secret"
+ACCOUNTS = [('mail.example.com', 'email@example.com', PASSWORD)]
+DESTINATION="other@example.com"
+
+youve_got_mail = False
+all_subjects = {}
+
+for account in ACCOUNTS:
+ mail = emailutils.get_imap(account)
+ these_subjects = []
+ for uid in emailutils.get_mail_uids(mail):
+ message = emailutils.get_message(mail, uid)
+ these_subjects.append(message['subject'])
+ youve_got_mail = True
+ all_subjects[account[1]] = these_subjects
+
+
+if youve_got_mail:
+ msg = ""
+ for account in all_subjects:
+ msg = msg + "# Messages for %s\n" % account
+ for subject in all_subjects[account]:
+ msg = msg + " * %s\n" % subject
+ msg = msg + "\n"
+
+ digest_message = message.Message()
+ digest_message.set_payload(msg)
+ digest_message['From'] = DESTINATION
+ digest_message['To'] = DESTINATION
+ digest_message['Subject'] = "Email Digest"
+
+ s = smtplib.SMTP_SSL('localhost', 2465)
+ s.sendmail(DESTINATION, DESTINATION, digest_message.as_string())
+ s.quit() \ No newline at end of file