newMessage = EmailMessage()
newMessage['Subject'] = "Check out the Grafana panel information"
newMessage['From'] = Sender_Email
newMessage['To'] = Reciever_Email
newMessage.set_content('Let me know what you think. Image attached!')
with open('image.png', 'rb') as f:
image_data = f.read()
image_type = imghdr.what(f.name)
image_name = f.name
newMessage.add_attachment(image_data, maintype='image', subtype=image_type, filename=image_name)
with smtplib.SMTP('mailserver.domain', 25) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo
smtp.login(Sender_Email, Password)
smtp.send_message(newMessage)
How about add new functionality - after capture PNG file send him to some EMAIL server/sender ?
See a working example code:
import smtplib import imghdr from email.message import EmailMessage
Sender_Email = "sender@somemailserver.domain" Reciever_Email = "reciever@somemailserver.domain" Password = "XXXXXXXXXXXXXXXXXXX"
newMessage = EmailMessage() newMessage['Subject'] = "Check out the Grafana panel information" newMessage['From'] = Sender_Email newMessage['To'] = Reciever_Email newMessage.set_content('Let me know what you think. Image attached!')
with open('image.png', 'rb') as f: image_data = f.read() image_type = imghdr.what(f.name) image_name = f.name
newMessage.add_attachment(image_data, maintype='image', subtype=image_type, filename=image_name) with smtplib.SMTP('mailserver.domain', 25) as smtp: smtp.ehlo() smtp.starttls() smtp.ehlo smtp.login(Sender_Email, Password) smtp.send_message(newMessage)