how to send an html email python code example
Example 1: send email python
from mailer import Mailer
mail = Mailer(email='[email protected]', password='your_password')
mail.send(receiver='[email protected]', subject='TEST', message='From Python!')
Example 2: send html smtp email python
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
def send_email():
sender = FROM_EMAIL
receiver = ["[email protected]","[email protected]"]
msg = MIMEMultipart()
msg['From'] = FROM_NAME
msg['To'] = TO_NAME
msg['Subject'] = SUBJECT
with open(HTML_TEMPLATE) as f:
html = f.read()
part = MIMEText(html, 'html')
msg.attach(part)
with smtplib.SMTP("smtp.gmail.com") as connection:
connection.starttls()
connection.login(CONNECTION USERNAME/EMAIL, CONNECTION PASSWORD)
connection.sendmail(sender, receiver, msg.as_string())