Ich habe ein Problem mit dem programmieren. Ich habe meinen Raspberry Pi in mein Smart Home eingebunden und will dass der Raspi an eine bestimmte email Adresse eine kurze Email mit einer statusmeldung versendet. Habe auch schon im Internet geschaut aber hat nicht funktioniert. Hat jemand Ahnung von python. Ich bin schon am verzweifeln
Raspberry Emailbenachrichtigung python3
-
-
-
Ok danke probiere ich mal aus
-
Raspbian Lite Stretch wird ohne sendmail installiert. Ohne sendmail dürfte der Email Versand mit diesem Python-Script nicht funktionieren.
-
Ich habe Raspbian Jessie aus Kompabilitätsproblemen. Auch diese Lösung funktioniert bei mir nicht
-
Ich würde es etwas anders machen...
Python
Alles anzeigen#Vorbereitung import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from os.path import basename def send_mail(send_from: str, subject: str, text: str, send_to: list, files= None): send_to= default_address if not send_to else send_to msg = MIMEMultipart() msg['From'] = send_from msg['To'] = ', '.join(send_to) msg['Subject'] = subject msg.attach(MIMEText(text)) for f in files or []: with open(f, "rb") as fil: ext = f.split('.')[-1:] attachedfile = MIMEApplication(fil.read(), _subtype = ext) attachedfile.add_header( 'content-disposition', 'attachment', filename=basename(f) ) msg.attach(attachedfile) smtp = smtplib.SMTP(host="smtp.gmail.com", port= 587) smtp.starttls() smtp.login(username,password) smtp.sendmail(send_from, send_to, msg.as_string()) smtp.close() #Nutzen username = 'my-address@gmail.com' password = 'top-secret' default_address = ['my-address2@gmail.com'] send_mail(send_from= username, subject="test", text="text", send_to= None, files= # selbsterklärend )
Aber ohne ein Chromjob, Intervall oder Timeout der auf sich selbst verweißt wird das nicht automatisiert ausgeführt....