#create a function to send the emails
def send_email (sender, receiver, sender_password, text_price):
#create a MIMEmultipart object
msg = MM()
msg['Subject'] = "Newest Etheruem Price !"
msg['From'] = sender
msg['To'] = receiver
#HTML for the message printed
HTML = """
<html>
<body>
<h1> Newest Etheruem Price !</h1>
<h2> """+text_price+""" </h2>
</body>
</html>
"""
#MIMEText oject
MTobj = MT(HTML, 'HTML')
#MIMEText ojbect attachment
msg.attach(MTobj)
#Secure socket layer SSL context object
SSL_context = ssl.create_default_context()
#Simple mail transfer protocol SMTP connection
server = smtplib.SMTP_SSL(host="smtp.gmail.com", port=465, context=SSL_context)
#login to email
server.login(sender, sender_passsword)
#send email
server.sendmail(sender, receiver, msg.as_string())
the line of code that wont work is the MIMEText obj with MTobj = MT(HTML, 'HTML'). I am not sure why the HTML is not defined, any help would be appreciated, thank you
Read more here: https://stackoverflow.com/questions/66339552/name-error-html-is-not-defined-using-mimetext-object
Content Attribution
This content was originally published by rsean at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.