From 20a8e6fea349de26199228385bca931e32e494d3 Mon Sep 17 00:00:00 2001 From: Niklas Elsbrock Date: Mon, 12 Jul 2021 00:53:36 +0200 Subject: [PATCH] =?UTF-8?q?"To"-Header=20zu=20E-Mail-Versand=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nateman/blueprints/auth.py | 4 ++-- nateman/emails.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/nateman/blueprints/auth.py b/nateman/blueprints/auth.py index 52806da..b31e0e7 100644 --- a/nateman/blueprints/auth.py +++ b/nateman/blueprints/auth.py @@ -342,7 +342,7 @@ def password_reset(): # Zurücksetzungsemail senden try: - emails.send_password_reset_mail(lehrer.email, new_token) + emails.send_password_reset_mail(lehrer.kuerzel, lehrer.email, new_token) except SMTPRecipientsRefused: flash(f"Es konnte keine E-Mail an {lehrer.email} gesendet werden.\n" f"Wahrscheinlich existiert diese Adresse nicht mehr.\n" @@ -453,7 +453,7 @@ def account(): token = util.random_uri_safe_string(32) # Bestätigungsemail senden try: - emails.send_confirmation_link_mail(new_email, token) + emails.send_confirmation_link_mail(g.lehrer.kuerzel, new_email, token) except SMTPRecipientsRefused: flash(f"Wir konnten keine Bestätigungsemail an {new_email} senden. " f"Wahrscheinlich existiert diese Adresse nicht.", "error") diff --git a/nateman/emails.py b/nateman/emails.py index 5e7f7ef..f881c9b 100644 --- a/nateman/emails.py +++ b/nateman/emails.py @@ -46,12 +46,13 @@ def _smtp_create() -> Union[smtplib.SMTP, smtplib.SMTP_SSL]: return smtp -def _send_mail(address: str, subject: str, content: str, content_type="html", content_charset="utf-8", - smtp: Optional[smtplib.SMTP] = None) -> None: +def _send_mail(name: str, address: str, subject: str, content: str, content_type="html", + content_charset="utf-8", smtp: Optional[smtplib.SMTP] = None) -> None: """ Sendet eine E-Mail mit den in der NateMan-Konfiguration angegebenen SMTP-Daten. - :param address: Adresse, zu der die E-Mail gesendet werden soll + :param name: Name des Empfängers + :param address: Adresse des Empfängers :param subject: Betreff der E-Mail :param content: Inhalt der E-Mail :param content_type: Inhaltstyp der E-Mail @@ -64,6 +65,7 @@ def _send_mail(address: str, subject: str, content: str, content_type="html", co msg = MIMEText(content, content_type, content_charset) msg["From"] = f"NateMan <{sender_address}>" + msg["To"] = f"{name} <{address}>" msg["Subject"] = subject smtp_param = smtp is not None @@ -86,16 +88,16 @@ def _send_mail(address: str, subject: str, content: str, content_type="html", co smtp.close() -def send_confirmation_link_mail(address: str, token: str) -> None: +def send_confirmation_link_mail(name: str, address: str, token: str) -> None: """Sendet die Bestätigungsemail nach dem Festlegen der E-Mail-Adresse.""" content = render_template("email/confirmation.html.j2", token=token) - _send_mail(address, "NateMan: Bestätigung der E-Mail-Adresse", content) + _send_mail(name, address, "NateMan: Bestätigung der E-Mail-Adresse", content) -def send_password_reset_mail(address: str, token: str) -> None: +def send_password_reset_mail(name: str, address: str, token: str) -> None: """Sendet die Passwortzurücksetzungsemail.""" content = render_template("email/password-reset.html.j2", token=token) - _send_mail(address, "NateMan: Passwortzurücksetzung", content) + _send_mail(name, address, "NateMan: Passwortzurücksetzung", content) def send_reminder_mails() -> int: @@ -134,7 +136,7 @@ def send_reminder_mails() -> int: content = render_template("email/reminder.html.j2", not_edited_list=not_edited_list) try: - _send_mail(lehrer.email, "NateMan: zur Erinnerung", content, smtp=smtp) + _send_mail(lehrer.kuerzel, lehrer.email, "NateMan: zur Erinnerung", content, smtp=smtp) except smtplib.SMTPRecipientsRefused as exc: logger.info(f"Erinnerungsemail an {lehrer} mit der Adresse {lehrer.email} konnte nicht versandt werden " f"(wahrscheinlich ungültige Adresse).", exc_info=exc)