So I made this program to send HTML emails using python. The reason I made this was to send personalized emails easily. But can't find a way to embed python variables to HTML. Is it not possible?
Do I need javascript for this? I don't have any JS knowledge at all.
Please let me know how I can do this.
import smtplib, ssl,getpass
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
#Mail server details
port=465
smtp_server="smtp.gmail.com"
#Account details
my_email="emailautomationpy@gmail.com"
password = getpass.getpass("Enter you password and press return\n")
#Receiver's details
receiver_email="emailautomationpy@gmail.com"
messeage= MIMEMultipart('alternative')
messeage["Subject"]= "Subject"
messeage["From"]= my_email
messeage["To"]= receiver_email
#HTML EMAIL
html = """\
<html>
<body>
<p>Hi,{name}<br>
How are you?<br>
</p>
</body>
</html>
"""
messeage.attach(MIMEText(html,"html"))
context = ssl.create_default_context()
try:
print("Sending your email... Please wait...")
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(my_email, password)
server.sendmail(
my_email,receiver_email,messeage.as_string()
)
print("\n(*) Email sent successfully (*)")
except:
print("An error occurred while sending the email")