2013-09-04 19:29:44 +02:00
|
|
|
#!/usr/bin/env python
|
2013-09-19 16:43:53 +02:00
|
|
|
# coding=utf-8
|
2013-09-04 19:29:44 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import os.path
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
import imaplib
|
|
|
|
|
|
|
|
email_config = {}
|
|
|
|
email_config_lines = open(os.path.expanduser("~/.msmtprc")).read().strip().split("\n")
|
|
|
|
for line in email_config_lines:
|
|
|
|
k,v = line.split()
|
|
|
|
email_config[k] = v
|
|
|
|
|
|
|
|
USERNAME = email_config['user']
|
|
|
|
PASSWORD = email_config['password']
|
|
|
|
|
|
|
|
people = """
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
########################################
|
|
|
|
people_list = people.strip().split('\n')
|
|
|
|
|
|
|
|
server = imaplib.IMAP4_SSL('imap.gmail.com')
|
|
|
|
server.login(USERNAME, PASSWORD)
|
|
|
|
|
2013-09-11 04:18:43 +02:00
|
|
|
if len(sys.argv) == 2:
|
|
|
|
template_name = sys.argv[1]
|
|
|
|
|
|
|
|
template = open("templates/%s.txt" % template_name).read()
|
|
|
|
|
|
|
|
def get_message(template, first_name):
|
|
|
|
message = "\n".join(template.strip().split("\n")[2:])
|
|
|
|
return message.replace("{{name}}", first_name)
|
|
|
|
|
|
|
|
def get_subject(template):
|
|
|
|
return template.split("\n")[0].strip()
|
|
|
|
|
2013-09-20 20:36:00 +02:00
|
|
|
send_count = 0
|
2013-09-04 19:29:44 +02:00
|
|
|
for person in people_list:
|
|
|
|
fields = person.split('\t')
|
2013-09-20 20:36:00 +02:00
|
|
|
name,email = fields[:2] #,realm,last_send,send_count,last_pointer,pointer_count,last_updates = fields
|
2013-09-04 19:29:44 +02:00
|
|
|
first_name = name.split()[0]
|
|
|
|
print first_name,name,email, '-', send_count
|
|
|
|
|
2013-09-11 04:18:43 +02:00
|
|
|
msg = MIMEText(get_message(template, first_name))
|
|
|
|
msg['Subject'] = get_subject(template)
|
2013-09-04 19:29:44 +02:00
|
|
|
msg['From'] = 'Waseem Daher <wdaher@zulip.com>'
|
|
|
|
msg['To'] = '%s <%s>' % (name,email,)
|
|
|
|
server.append("[Gmail]/Drafts",
|
|
|
|
'',
|
|
|
|
imaplib.Time2Internaldate(time.time()),
|
|
|
|
str(msg))
|
|
|
|
|
|
|
|
server.logout()
|