Skip to content
Permalink
b40cdafc50
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
53 lines (41 sloc) 1.68 KB
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def sendEmails (sourceAddress, addresses, alarmDate, alarmLocation, alarmMessage, alarmSource):
msg = MIMEMultipart()
msg['Subject'] = alarmMessage
msg['From'] = sourceAddress
msg['To'] = addresses
content = alarmMessage + '\n' + \
'Date: ' + str(alarmDate) + '\n' + \
'Location: ' + alarmLocation + '\n' + \
'Source: ' + alarmSource
msg.attach(MIMEText(content, 'plain'))
s = smtplib.SMTP('mail.fhi-berlin.mpg.de')
s.sendmail(sourceAddress, addresses, msg.as_string())
s.quit()
def getMailAddresses (currentHour, mailAddresses, timePeriods):
periods = timePeriods.split(';')
foundAPeriod = False
for n, period in enumerate(periods):
try:
times = period.split('-')
if int(times[0]) <= currentHour < int(times[1]):
foundAPeriod = True
break
except:
errorMessage = "ERROR: Something is wrong with the given period: " + period + " Please check it."
return errorMessage
if not foundAPeriod:
errorMessage = "ERROR: The current hour, " + str(currentHour) + ", is not contained in any of the time periods " \
"specified in the SETTINGS file."
return errorMessage
try:
addresses = mailAddresses.split(';')
except IndexError:
errorMessage = "ERROR: There are no e-mails specified for the current time period, " + period + \
"Please check again the SETTINGS file"
return errorMessage
return addresses[n]