tsi 3 éve
szülő
commit
6268d308f8
1 módosított fájl, 42 hozzáadás és 0 törlés
  1. 42 0
      send_email_restart.py

+ 42 - 0
send_email_restart.py

@@ -0,0 +1,42 @@
+import urllib.request, tempfile, smtplib, email, time
+from datetime import datetime, timedelta
+
+
+tmpdir = tempfile.TemporaryDirectory() 
+
+
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from email.mime.image import MIMEImage
+
+# Define these once; use them twice!
+strFrom = 'pv-tannenstr@web.de'
+strTo = ["tobias.siegel@outlook.com", "wsiegel@web.de"]
+
+# Create the root message and fill in the from, to, and subject headers
+msgRoot = MIMEMultipart('related')
+msgRoot['Subject'] = 'Darmstadt Neustart RPI'
+msgRoot['From'] = strFrom
+msgRoot['To'] = ",".join(strTo)
+msgRoot.preamble = 'This is a multi-part message in MIME format.'
+
+# Encapsulate the plain and HTML versions of the message body in an
+# 'alternative' part, so message agents can decide which they want to display.
+msgAlternative = MIMEMultipart('alternative')
+msgRoot.attach(msgAlternative)
+
+msgText = MIMEText('')
+msgAlternative.attach(msgText)
+
+
+# Send the email (this example assumes SMTP authentication is required)
+import smtplib, ssl
+context = ssl.create_default_context()
+with smtplib.SMTP('smtp.web.de', 587) as server:
+    server.ehlo()  # Can be omitted
+    server.starttls(context=context)
+    server.ehlo()  # Can be omitted
+    server.login(strFrom, 'PV-Tannenstr')
+    server.sendmail(strFrom, strTo, msgRoot.as_string())
+
+tmpdir.cleanup()