import smtplib
from email.utils import formatdate
from os.path import basename
from email.mime.text import MIMEText
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
EMAIL_SENDER_ADDRESS = ''
EMAIL_SENDER_PASSWORD = ''
def sendEmail(message, subject):
#Expéditeur
from_email = EMAIL_SENDER_ADDRESS
from_password = EMAIL_SENDER_PASSWORD
#Destination
to_email = [Env.EMAIL_RECIEVE_ADDRESS]
#Le contenu de l'e-mail
msg = MIMEMultipart()
body = MIMEText(message, "html")
msg.attach(body)
msg["Subject"] = subject
msg["To"] = ",".join(to_email)
msg["From"] = from_email
gmail = smtplib.SMTP("smtp.gmail.com", 587)
gmail.starttls()
gmail.login(from_email, from_password)
gmail.send_message(msg)
Recommended Posts