From cdbc3061d59c131dd16b975a8e7d5ea0635e6671 Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Tue, 10 Oct 2017 23:42:56 +0200 Subject: [PATCH] Set Reply-To for todo and protocol mails --- tasks.py | 19 ++++++++++++------- utils.py | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tasks.py b/tasks.py index 483df5e..bac430d 100644 --- a/tasks.py +++ b/tasks.py @@ -579,10 +579,14 @@ def send_reminder_async(reminder_id, protocol_id): reminder_text = render_template("reminder-mail.txt", reminder=reminder, protocol=protocol) if reminder.send_public: print("sending public reminder mail to {}".format(protocol.protocoltype.public_mail)) - send_mail(protocol, protocol.protocoltype.public_mail, "Tagesordnung der {}".format(protocol.protocoltype.name), reminder_text) + send_mail(protocol, protocol.protocoltype.public_mail, + "Tagesordnung der {}".format(protocol.protocoltype.name), + reminder_text, reply_to=protocol.protocoltype.public_mail) if reminder.send_private: print("sending private reminder mail to {}".format(protocol.protocoltype.private_mail)) - send_mail(protocol, protocol.protocoltype.private_mail, "Tagesordnung der {}".format(protocol.protocoltype.name), reminder_text) + send_mail(protocol, protocol.protocoltype.private_mail, + "Tagesordnung der {}".format(protocol.protocoltype.name), + reminder_text, reply_to=protocol.protocoltype.private_mail) def send_protocol_private(protocol): send_protocol_async.delay(protocol.id, show_private=True) @@ -640,18 +644,19 @@ def send_todomails_async(protocol_id): continue to_addr = todomail.get_formatted_mail() mail_content = render_template("todo-mail.txt", protocol=protocol, todomail=todomail, todos=grouped_todos[user]) - send_mail(protocol, to_addr, subject, mail_content) + send_mail(protocol, to_addr, subject, mail_content, + reply_to=protocol.protocoltype.private_mail) -def send_mail(protocol, to_addr, subject, content, appendix=None): +def send_mail(protocol, to_addr, subject, content, appendix=None, reply_to=None): if to_addr is not None and len(to_addr.strip()) > 0: - send_mail_async.delay(protocol.id, to_addr, subject, content, appendix) + send_mail_async.delay(protocol.id, to_addr, subject, content, appendix, reply_to) @celery.task -def send_mail_async(protocol_id, to_addr, subject, content, appendix): +def send_mail_async(protocol_id, to_addr, subject, content, appendix, reply_to): with app.app_context(): protocol = Protocol.query.filter_by(id=protocol_id).first() try: - mail_manager.send(to_addr, subject, content, appendix) + mail_manager.send(to_addr, subject, content, appendix, reply_to) except Exception as exc: error = protocol.create_error("Sending Mail", "Sending mail failed", str(exc)) db.session.add(error) diff --git a/utils.py b/utils.py index 1d3eb66..f897a76 100644 --- a/utils.py +++ b/utils.py @@ -75,7 +75,7 @@ class MailManager: self.use_tls = getattr(config, "MAIL_USE_TLS", True) self.use_starttls = getattr(config, "MAIL_USE_STARTTLS", False) - def send(self, to_addr, subject, content, appendix=None): + def send(self, to_addr, subject, content, appendix=None, reply_to=None): if (not self.active or not self.hostname or not self.from_addr): @@ -85,6 +85,8 @@ class MailManager: msg["To"] = to_addr msg["Subject"] = subject msg["Message-ID"] = "<{}@{}>".format(uuid4(), getfqdn()) + if reply_to is not None: + msg["Reply-To"] = reply_to msg.attach(MIMEText(content, _charset="utf-8")) if appendix is not None: for name, file_like in appendix: -- GitLab