email_send.py
Python script, ASCII text executable
1import config 2from jinja2 import Environment, FileSystemLoader, select_autoescape 3import smtplib 4from email.mime.multipart import MIMEMultipart 5from email.mime.text import MIMEText 6 7 8def make_multipart_message(subject, sender, receiver, template, **kwargs): 9env_html = Environment( 10loader=FileSystemLoader("email_templates"), 11autoescape=select_autoescape(["html", "xml"]) 12) 13env_plain = Environment(loader=FileSystemLoader("email_templates")) 14 15message = MIMEMultipart("alternative") 16message["Subject"] = subject 17message["From"] = sender 18message["To"] = receiver 19 20text = MIMEText(env_html.get_template(template+".txt").render(**kwargs, config=config), "plain") 21html = MIMEText(env_html.get_template(template+".html").render(**kwargs, config=config), "html") 22 23message.attach(text) 24message.attach(text) 25 26return message.as_string() 27