ich habe diese Mailfunktion:
Code: Alles auswählen
#!/usr/bin/env python3
import datetime
import smtplib, sys, time
from email.mime.text import MIMEText
from email.header import Header
now = datetime.datetime.now()
zeit = now.strftime('%d.%m.%Y, %H:%M:%S')
frm = "ich@gmail.com"
to = "ich@gmail.com"
smtpHost = "smtp.gmail.com"
smtpPort = 465
smtpUser = "ich@gmail.com"
smtpPassword = "SuperGeheimesPasswort"
subj = "Falsche Karte an Tür"
text = "Es wurde ein falscher Code an der Tür verwendet. "
msg = f"{text} {zeit} Uhr."
mime = MIMEText(msg, "plain", "utf-8")
mime["from"] = frm
mime["to"] = to
mime["Subject"] = Header(subj, "utf-8")
def mailversand():
try:
with smtplib.SMTP_SSL(smtpHost, smtpPort) as smtp:
smtp.login(smtpUser, smtpPassword)
smtp.sendmail(frm, to, mime.as_string())
except smtplib.SMTPServerDisconnected:
print("Server hat Verbindung abgebrochen")
else:
print("Mail verschickt")
__name__=="__main__"
Code: Alles auswählen
#!/usr/bin/env python3
from mailtome import mailversand
from time import sleep
mailversand()
sleep(120)
mailversand()
Wie bekomme ich die tatsächliche Zeit für die jeweilige Mail?