Senden Sie mit Python mit Google Mail
Fazit
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):
#Absender
from_email = EMAIL_SENDER_ADDRESS
from_password = EMAIL_SENDER_PASSWORD
#Ziel
to_email = [Env.EMAIL_RECIEVE_ADDRESS]
#Der Inhalt der 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)