Commit 1542ec8d authored by Henrik Hüttemann's avatar Henrik Hüttemann

Add functionality to send mails to multiple recipients.

Signed-off-by: Henrik Hüttemann's avatarHerHde <mail@herh.de>
parent 93324a8d
MAIL_FROM = "events@example.com"
MAIL_TO = "info@example.com"
MAIL_TO = "info@example.com" # For multiple recipients write them as a ["list", "of", "addresses"].
MAIL_SUBJECT = "[Events] Termine vom {{ date_min.date }} bis {{ date_max.date }}" # This is parsed as a Jinja2-template.
SMTP_HOST = "mail.example.com"
......
......@@ -221,19 +221,25 @@ def generate_output(event_list):
def send_mail(content):
"""Send out an email."""
msg = Message()
msg.set_payload(content[0], "utf-8")
msg["Subject"] = content[1]
msg["From"] = config.MAIL_FROM
msg["To"] = config.MAIL_TO
server = smtplib.SMTP(config.SMTP_HOST, config.SMTP_PORT)
server.ehlo()
server.starttls()
server.ehlo()
server.login(config.SMTP_USER, config.SMTP_PASS)
server.sendmail(config.MAIL_FROM, config.MAIL_TO, msg.as_string())
server.quit()
if isinstance(config.MAIL_TO, list):
mail_to_list = config.MAIL_TO
else:
mail_to_list = [config.MAIL_TO]
for mail_to in mail_to_list:
msg = Message()
msg.set_payload(content[0], "utf-8")
msg["Subject"] = content[1]
msg["From"] = config.MAIL_FROM
msg["To"] = mail_to
server = smtplib.SMTP(config.SMTP_HOST, config.SMTP_PORT)
server.ehlo()
server.starttls()
server.ehlo()
server.login(config.SMTP_USER, config.SMTP_PASS)
server.sendmail(config.MAIL_FROM, mail_to, msg.as_string())
server.quit()
def main():
events = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment