#!/usr/bin/python3 import smtplib import yaml from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage from email import encoders creds = yaml.safe_load(open('creds.yaml', 'r')) attachment = 'saved.png' body = "The latest pfSense Dashboard." msg = MIMEMultipart() msg['From']=creds['from_email'] msg['To']=creds['to_email'] msg['Subject']='pfSense Status' msgText = MIMEText( '%s

' % (body, attachment), 'html') msg.attach(msgText) fp = open(attachment, 'rb') img = MIMEImage(fp.read()) fp.close img.add_header('Content-ID', "<{}>".format(attachment)) msg.attach(img) server = smtplib.SMTP(creds['smtp_server'], 587) server.starttls() server.login(creds['smtp_user'],creds['smtp_password']) server.sendmail(creds['from_email'], creds['to_email'], msg.as_string()) server.quit()