I am sending an email in Python and am trying to pass a variable in the HTML. I see that this can be done with "formatstring".format
, but I am unable to do it successfully. Here's a short(er) version of what I have:
email_to = []
email_apiendpoint = []
for data_item in json.loads(email_curl_str, strict=False)['data']:
email_to.append(data_item['emailAddress'])
email_apiendpoint.append(data_item['apiEndpoint'])
ddn = random.randint(200, 400)
email_msg = MIMEMultipart('alternative')
email_msg['Subject'] = "Link"
email_msg['From'] = email_from
email_msg['To'] = email_to[0]
email_text = "Plain text here."
email_html = """\
<html>
<head>
</head>
<body>
<p>Compare to: {ddn}</p>
</body>
</html>
""".format(ddn=ddn)
part1 = MIMEText(email_text, 'plain')
part2 = MIMEText(email_html, 'html')
email_user = ''
email_pw = ''
smtpserver = smtplib.SMTP("mauimail.prxy.com")
def send_email():
email_msg.attach(part1)
email_msg.attach(part2)
smtp.server.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(email_user, email_pw)
smtpserver.sendmail(email_from, email_to[0], email_msg.as_string())
smtpserver.quit()
This results in:
""".format(ddn=ddn)
KeyError: ' border'
What am I doing wrong?
Compare to: 321
``` So can you edit in more of the code? – Jeff_Hd Aug 20 '15 at 22:47