I'm using a script that extracts data from a text file, works on a Python script and sends an email from Python. It has a built-in HTML so that the email that is sent has the format I want. My question is: Is there any way to insert Python variables into the HTML I have as a template? I attach the code that I am using to see if someone can help me. Thank you.
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
from_address = "santiago@madketing.com.ar"
to_address = "santiago@madketing.com.ar"
message = MIMEMultipart("alternative")
name = "Pepito"
number = "123456789"
email = "pepito@pepito.com"
text = "Nuevo Lead"
html = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Nuevo Lead</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body style="margin: 0; padding: 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center">
<img src="https://image.ibb.co/caP9CG/company_logo_blanco.jpg" alt="company_logo_blanco" border="0"></a>
</td>
</tr>
<tr>
<td align="center">
<h1> Nuevo Lead </h1>
</td>
</tr>
<tr>
<td>
Nombre:
</td>
</tr>
<tr>
<td>
Telefono:
</td>
</tr>
<tr>
<td>
Email:
</td>
</tr>
</table>
</body>
</html>
"""
part1 = MIMEText(text, "plain")
part2 = MIMEText(html, "html")
message.attach(part1)
message.attach(part2)
message["From"] = "Nuevo Lead!"
message["To"] = to_address
message["Subject"] = "Correo de prueba"
smtp = SMTP("Server")
smtp.login(from_address, "Password")
smtp.sendmail(from_address, to_address, message.as_string())
smtp.quit()