Show/Hide
EMAILRECEIVER = ""
EMAILSENDER = ""
MAILSERVER = ""
MAILSERVERPORT = ""
EMAILSENDER = ""
def buildMail(self):
mailText = ""
# build your mail here string by string (mailText += "")
return mailText
def sendMail(self, hosts, awakeList, failedList, statusUnknownList):
if EMAILRECEIVER and EMAILSENDER and MAILSERVER and MAILSERVERPORT:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
smtp = smtplib.SMTP()
smtp.connect(MAILSERVER, MAILSERVERPORT)
# define subject here
subject = ""
msgRoot = MIMEMultipart("alternative")
msgRoot['Subject'] = Header(subject, "utf-8")
msgRoot['From'] = "wolserver <" + EMAILSENDER + ">"
msgRoot['To'] = EMAILRECEIVER
mailContent = MIMEText(wakeup.buildMail(self))
mailText = MIMEText(mailContent, "plain", "utf-8")
msgRoot.attach(mailText)
try:
smtp.sendmail(EMAILSENDER, EMAILRECEIVER, msgRoot.as_string())
except:
print(self, "Failed to send mail to " + EMAILRECEIVER + " | Check your settings!")
print(traceback.format_exc())
else:
print(self, "Mailing disabled or not configured properly.")