| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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 asdthe 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()
|