-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.py
More file actions
30 lines (26 loc) · 1023 Bytes
/
send_email.py
File metadata and controls
30 lines (26 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from datetime import date
import json
import smtplib
def is_today(date_string):
# I assume that the dates are in mm/dd format
month, day = date_string.split('/')
return date.today().month == int(month) and date.today().day == int(day)
def send_email(receiver, config):
def construct_address():
if '@' in receiver:
return receiver
else:
return receiver + config['receiver_domain_name']
server = smtplib.SMTP(config['mail_server'])
server.starttls()
server.login(config['username'], config['password'])
server.sendmail(config['from_email'], construct_address(), 'Subject: %s\n\n%s' % (config['msg_subject'], config['msg_text']))
server.quit()
install_dir = '/usr/local/bin/send_email/'
config = json.loads(open('%sCONFIG.private' % (install_dir)).read())
schedule_file = open(config['email_schedule'])
for line in schedule_file.read().splitlines():
date_string, receiver = line.split('\t')
if is_today(date_string):
send_email(receiver, config)
print 'Sent email to %s' % (receiver)