Commit cdbc3061 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Set Reply-To for todo and protocol mails

parent 6cc4f81d
...@@ -579,10 +579,14 @@ def send_reminder_async(reminder_id, protocol_id): ...@@ -579,10 +579,14 @@ def send_reminder_async(reminder_id, protocol_id):
reminder_text = render_template("reminder-mail.txt", reminder=reminder, protocol=protocol) reminder_text = render_template("reminder-mail.txt", reminder=reminder, protocol=protocol)
if reminder.send_public: if reminder.send_public:
print("sending public reminder mail to {}".format(protocol.protocoltype.public_mail)) 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: if reminder.send_private:
print("sending private reminder mail to {}".format(protocol.protocoltype.private_mail)) 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): def send_protocol_private(protocol):
send_protocol_async.delay(protocol.id, show_private=True) send_protocol_async.delay(protocol.id, show_private=True)
...@@ -640,18 +644,19 @@ def send_todomails_async(protocol_id): ...@@ -640,18 +644,19 @@ def send_todomails_async(protocol_id):
continue continue
to_addr = todomail.get_formatted_mail() to_addr = todomail.get_formatted_mail()
mail_content = render_template("todo-mail.txt", protocol=protocol, todomail=todomail, todos=grouped_todos[user]) 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: 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 @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(): with app.app_context():
protocol = Protocol.query.filter_by(id=protocol_id).first() protocol = Protocol.query.filter_by(id=protocol_id).first()
try: try:
mail_manager.send(to_addr, subject, content, appendix) mail_manager.send(to_addr, subject, content, appendix, reply_to)
except Exception as exc: except Exception as exc:
error = protocol.create_error("Sending Mail", "Sending mail failed", str(exc)) error = protocol.create_error("Sending Mail", "Sending mail failed", str(exc))
db.session.add(error) db.session.add(error)
......
...@@ -75,7 +75,7 @@ class MailManager: ...@@ -75,7 +75,7 @@ class MailManager:
self.use_tls = getattr(config, "MAIL_USE_TLS", True) self.use_tls = getattr(config, "MAIL_USE_TLS", True)
self.use_starttls = getattr(config, "MAIL_USE_STARTTLS", False) 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 if (not self.active
or not self.hostname or not self.hostname
or not self.from_addr): or not self.from_addr):
...@@ -85,6 +85,8 @@ class MailManager: ...@@ -85,6 +85,8 @@ class MailManager:
msg["To"] = to_addr msg["To"] = to_addr
msg["Subject"] = subject msg["Subject"] = subject
msg["Message-ID"] = "<{}@{}>".format(uuid4(), getfqdn()) msg["Message-ID"] = "<{}@{}>".format(uuid4(), getfqdn())
if reply_to is not None:
msg["Reply-To"] = reply_to
msg.attach(MIMEText(content, _charset="utf-8")) msg.attach(MIMEText(content, _charset="utf-8"))
if appendix is not None: if appendix is not None:
for name, file_like in appendix: for name, file_like in appendix:
......
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