-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_email.py
executable file
·32 lines (27 loc) · 1.36 KB
/
send_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
#!/usr/bin/env python3
import util
import sys
import argparse
def main():
for item in context:
email_body = template.render(item)
try:
print("Sent to " + item['email'])
if not args.quiet:
print(email_body)
if not args.dryrun:
util.send_email(item['email'],subject, email_body)
except:
print("missing email address")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("context", help="Path to a CSV file with the data context for the template. Each row in the CSV will result in one sent email. The template is filled with associated data from a given row. Must have a column named 'email' for To: address.")
parser.add_argument("template",help="Path to a Jinja2 template file that can be filled by the context")
parser.add_argument("subject", help="Quoted string with email's subject line, subject string is NOT filled as a template")
parser.add_argument("-q","--quiet", help="Supress printing of all filled templates.", action="store_true")
parser.add_argument("-d", "--dryrun", help="Don't actually send emails, just print them to screen.", action="store_true")
args = parser.parse_args()
context = util.csv2dict(args.context)
template = util.readtemplate(args.template)
subject = args.subject
main()