"To"-Header zu E-Mail-Versand hinzugefügt

This commit is contained in:
2021-07-12 00:53:36 +02:00
parent c7f0c6a1c4
commit 20a8e6fea3
2 changed files with 12 additions and 10 deletions
+2 -2
View File
@@ -342,7 +342,7 @@ def password_reset():
# Zurücksetzungsemail senden # Zurücksetzungsemail senden
try: try:
emails.send_password_reset_mail(lehrer.email, new_token) emails.send_password_reset_mail(lehrer.kuerzel, lehrer.email, new_token)
except SMTPRecipientsRefused: except SMTPRecipientsRefused:
flash(f"Es konnte keine E-Mail an {lehrer.email} gesendet werden.\n" flash(f"Es konnte keine E-Mail an {lehrer.email} gesendet werden.\n"
f"Wahrscheinlich existiert diese Adresse nicht mehr.\n" f"Wahrscheinlich existiert diese Adresse nicht mehr.\n"
@@ -453,7 +453,7 @@ def account():
token = util.random_uri_safe_string(32) token = util.random_uri_safe_string(32)
# Bestätigungsemail senden # Bestätigungsemail senden
try: try:
emails.send_confirmation_link_mail(new_email, token) emails.send_confirmation_link_mail(g.lehrer.kuerzel, new_email, token)
except SMTPRecipientsRefused: except SMTPRecipientsRefused:
flash(f"Wir konnten keine Bestätigungsemail an {new_email} senden. " flash(f"Wir konnten keine Bestätigungsemail an {new_email} senden. "
f"Wahrscheinlich existiert diese Adresse nicht.", "error") f"Wahrscheinlich existiert diese Adresse nicht.", "error")
+10 -8
View File
@@ -46,12 +46,13 @@ def _smtp_create() -> Union[smtplib.SMTP, smtplib.SMTP_SSL]:
return smtp return smtp
def _send_mail(address: str, subject: str, content: str, content_type="html", content_charset="utf-8", def _send_mail(name: str, address: str, subject: str, content: str, content_type="html",
smtp: Optional[smtplib.SMTP] = None) -> None: content_charset="utf-8", smtp: Optional[smtplib.SMTP] = None) -> None:
""" """
Sendet eine E-Mail mit den in der NateMan-Konfiguration angegebenen SMTP-Daten. 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 subject: Betreff der E-Mail
:param content: Inhalt der E-Mail :param content: Inhalt der E-Mail
:param content_type: Inhaltstyp 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 = MIMEText(content, content_type, content_charset)
msg["From"] = f"NateMan <{sender_address}>" msg["From"] = f"NateMan <{sender_address}>"
msg["To"] = f"{name} <{address}>"
msg["Subject"] = subject msg["Subject"] = subject
smtp_param = smtp is not None 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() 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.""" """Sendet die Bestätigungsemail nach dem Festlegen der E-Mail-Adresse."""
content = render_template("email/confirmation.html.j2", token=token) 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.""" """Sendet die Passwortzurücksetzungsemail."""
content = render_template("email/password-reset.html.j2", token=token) 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: 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) content = render_template("email/reminder.html.j2", not_edited_list=not_edited_list)
try: 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: except smtplib.SMTPRecipientsRefused as exc:
logger.info(f"Erinnerungsemail an {lehrer} mit der Adresse {lehrer.email} konnte nicht versandt werden " logger.info(f"Erinnerungsemail an {lehrer} mit der Adresse {lehrer.email} konnte nicht versandt werden "
f"(wahrscheinlich ungültige Adresse).", exc_info=exc) f"(wahrscheinlich ungültige Adresse).", exc_info=exc)