Danke

Code: Alles auswählen
# sends mail notification
def sendmail(receiver, subject, content, sendAsHtml, link):
global mailsession
if sendAsHtml:
baseurl = None
if link != None:
content = '<p><a href="' + link + '">' + subject + '</a></p>\n' + content
baseurl = urljoin(link, '/')
mail = MIMEText('<html><head><title>' + subject + '</title>' + ('<base href="' + baseurl + '">' if baseurl else '') + '</head><body>' + content + '</body></html>', 'html', defaultEncoding)
else:
if link != None:
content = link + '\n\n' + content
mail = MIMEText(content, 'text', defaultEncoding)
mail['From'] = config.sender
mail['To'] = receiver
mail['Subject'] = Header(subject, defaultEncoding)
# initialize session once, not each time this method gets called
if mailsession is None:
mailsession = smtplib.SMTP(config.smtphost, config.smtpport)
if config.useTLS:
mailsession.ehlo()
mailsession.starttls()
if config.smtpusername is not None:
mailsession.login(config.smtpusername, config.smtppwd)
mailsession.sendmail(config.sender, receiver.split(','), mail.as_string())
Code: Alles auswählen
else:
if link != None:
content = link + '\n\n' + content
mail = MIMEText(content, 'text', defaultEncoding)
Code: Alles auswählen
# start polling sites
for site in config.sites:
print('polling site [' + site['shortname'] + '] ...')
parseResult = parseSite(site)
receiver = site.get('receiver', config.receiver)
# if something went wrong, notify the user
if parseResult['warning']:
subject = '[' + site['shortname'] + '] WARNING'
print('WARNING: ' + parseResult['warning'])
if config.enableMailNotifications:
sendmail(receiver, subject, parseResult['warning'], False, None)
if config.enableRSSFeed:
feedXML.xpath('//channel')[0].append(genFeedItem(subject, parseResult['warning'], site['uri'], 0))
else:
# otherwise, check which parts of the site were updated
changes = 0
fileContents = getFileContents(site['shortname'])
i = 0
for content in parseResult['contents']:
if content not in fileContents:
changes += 1
subject = '[' + site['shortname'] + '] ' + parseResult['titles'][i]
print(' ' + subject)
if config.enableMailNotifications and len(fileContents) > 0:
sendmail(receiver, subject, content, (site.get('type', 'html') == 'html'), site['uri'])
if config.enableRSSFeed:
feedXML.xpath('//channel')[0].append(genFeedItem(subject, content, site['uri'], changes))
i += 1
if changes > 0:
storeFileContents(site['shortname'], parseResult)
print(' ' + str(changes) + ' updates')
Code: Alles auswählen
if config.enableMailNotifications and len(fileContents) > 0:
sendmail(receiver, subject, content, (site.get('type', 'html') == 'html'), site['uri'])
Code: Alles auswählen
...sendmail(receivererror, subject...