-
Notifications
You must be signed in to change notification settings - Fork 1
/
on_call_email.py
49 lines (39 loc) · 1.06 KB
/
on_call_email.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import csv
import os
import smtplib
from email.mime.text import MIMEText
import properties
#put your from and to address here
fromaddr = properties.props['from_addr']
#put your smtp server here
smtp_server = properties.props['smtp_server']
file_path = os.path.relpath('./'+properties.props['email_addr_filename'])
addr_book = {}
def lookup_addr():
global addr_book
print file_path
f = open( file_path, 'rU' ) #open the file in read universal mode
for line in f:
print line
#name,email = line.split(',')
data = line.split(',')
name = data[0]
email = data[1]
addr_book[name]=email
f.close()
def send_email(name):
global addr_book
if not name:
print 'name is required'
return;
#email body
msg = MIMEText('get ready')
#put your from and to address here
msg['Subject'] = 'You are on call'
msg['From'] = fromaddr
toaddr = addr_book[name]
msg['To'] = toaddr
s = smtplib.SMTP(smtp_server)
print "send email to %s" % toaddr
s.sendmail(fromaddr, [toaddr], msg.as_string())
s.quit()