| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import urllib.request, tempfile, smtplib, email, time
- from datetime import datetime
- tmpdir = tempfile.TemporaryDirectory()
- urllib.request.urlretrieve("http://192.168.178.201:3000/render/d-solo/-wCxs6mgk/solaranlage?orgId=1&refresh=10s&panelId=2&from=" + str((1000*int(time.time()))-(24*3600000)) + "&to=" + str(1000*int(time.time())) + "&width=600&height=300&tz=Europe%2FBerlin", tmpdir.name + "/leistung.png")
- # Send an HTML email with an embedded image and a plain text message for
- # email clients that don't want to display the HTML.
- 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 = 'net_flix_11@outlook.de'
- strTo = ["tobias.siegel@outlook.com", "t.siegel91@gmail.com","wsiegel@web.de"]
- # Create the root message and fill in the from, to, and subject headers
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = datetime.today().strftime('%Y-%m-%d') + ' Solaranlage'
- 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('This is the alternative plain text message.')
- msgAlternative.attach(msgText)
- # We reference the image in the IMG SRC attribute by the ID we give it below
- msgText = MIMEText('<img src="cid:image1">', 'html')
- msgAlternative.attach(msgText)
- # This example assumes the image is in the current directory
- fp = open(tmpdir.name + '/leistung.png', 'rb')
- msgImage = MIMEImage(fp.read())
- fp.close()
- # Define the image's ID as referenced above
- msgImage.add_header('Content-ID', '<image1>')
- msgRoot.attach(msgImage)
- # Send the email (this example assumes SMTP authentication is required)
- import smtplib, ssl
- context = ssl.create_default_context()
- with smtplib.SMTP('smtp.outlook.com', 587) as server:
- server.ehlo() # Can be omitted
- server.starttls(context=context)
- server.ehlo() # Can be omitted
- server.login(strFrom, 'kathrein47')
- server.sendmail(strFrom, strTo, msgRoot.as_string())
- tmpdir.cleanup()
|