I have a python script which generates some HTML code to send via email. Within the script there is a variable (tweet), that I would like to include the content of in the email.
Here is the code that generates the HTML for the email:
msg.add_alternative("""\
<!DOCTYPE html>
<html>
<body>
<p>Hi Human,</p>
<p>If you are seeing this, it means that you have received my email. Check out these images!</p>
<p>Best,</p>
<p>Simon</p>
<img src="cid:image1" ><br>
</body>
</html>
""", subtype='html')
I would like to add the variable ‘tweet’ into the body of the HTML code but dont know how to break the HTML and insert the variable and continue the HTML to finish.
Can someone help please…..Id be so grateful….thankyou sooo much.
Cheers
Simon
>Solution :
you have a few options to add variable to a string:
- using
format–
"data is {0}, I'm {1}".format(name, id)
- using
f"text text {your variable}"
I`m not sure where you want to add your variable so I hope this will help