I'm trying to create a function that e-mails an HTML File with CSS and everything. I'm trying to figure out how to pass variables into my HTML. The HTML code is in a separate file called index.html
FILE 1 app.py
def mailer2(addr_from,addr_to, title, password):
# Define SMTP email server details
smtp_server = 'smtp.gmail.com'
smtp_user = addr_from
smtp_pass = password
# Construct email
msg = MIMEMultipart('alternative')
msg['To'] = addr_to
msg['From'] = addr_from
msg['Subject'] = 'Test Email From Me'
html = urllib.urlopen('index.html').read().format(first_header = 'hi')
part2 = MIMEText(html, 'html')
msg.attach(part2)
s = smtplib.SMTP(smtp_server,587)
s.starttls()
s.login(smtp_user,smtp_pass)
s.sendmail(addr_from, addr_to, msg.as_string())
s.quit()
In my HTML code,
<div class="contentEditable" >
<h2>{first_header}</h2>
I expect hi
to fill in the spot of first_header
, but instead I get:
html = urllib.urlopen('index.html').read().format(first_header='goodbye') KeyError: 'padding'
Not sure what the issue is here. Could someone please help me out?