Answer the question
In order to leave comments, you need to log in
How to send email via HTML code in Python?
Greetings, I encountered such a problem, there is an html code - a letter template, there is a Python code that sends messages. So Here's how I can paste the code from this file so that the html email template is sent.
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
msg = MIMEMultipart()
message = 'Test_01'
password = "password"
msg['From'] = "mail"
msg['Subject'] = "Test_02"
msg['To'] = 'adress'
msg.attach(MIMEText(message, 'plain')
server = smtplib.SMTP('smtp.yandex.ru: 587')
server.starttls()
server.login(msg['From'], password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
Answer the question
In order to leave comments, you need to log in
import email.message
import smtplib
msg = email.message.Message()
msg['Subject'] = 'foo'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg.add_header('Content-Type','text/html')
msg.set_payload('Body of <b>message</b>')
# Send the message via local SMTP server.
s = smtplib.SMTP('localhost')
s.starttls()
s.login(email_login,
email_passwd)
s.sendmail(msg['From'], [msg['To']], msg.as_string())
s.quit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question