# coding: utf-8 """ Email notifications. """ from __future__ import absolute_import, print_function, unicode_literals import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def send_email(server, port, subject, _from, to, txt, html): if len(to) == 0: LOGGER.warn("No recipients for the email notifications, aborting.") return server = smtplib.SMTP(server, port) msg = MIMEMultipart('alternative') msg['Subject'] = subject msg['From'] = _from msg['To'] = ', '.join(to) msg.attach(MIMEText(txt, 'plain', 'utf-8')) msg.attach(MIMEText(html, 'html', 'utf-8')) server.sendmail(_from, to, msg.as_string()) server.quit() def send_notification(config, flats): # Don't send an email if there are no new flats. if len(flats) == 0: return txt = u'Hello dear user,\n\nThe following new flats have been found:\n\n' html = """
Hello dear user!
The following new flats have been found: