diff --git a/Web/modules/database/settings.py b/Web/modules/database/settings.py index 0d9bb00..78bf876 100644 --- a/Web/modules/database/settings.py +++ b/Web/modules/database/settings.py @@ -278,6 +278,7 @@ INVENTORY_MODULE_ENABLED = _TenantAwareBool('inventory', _get(_conf, ['modules', TERMINPLAN_MODULE_ENABLED = _TenantAwareBool('terminplan', _get(_conf, ['modules', 'terminplan', 'enabled'], DEFAULTS['modules']['terminplan']['enabled'])) LIBRARY_MODULE_ENABLED = _TenantAwareBool('library', _get(_conf, ['modules', 'library', 'enabled'], DEFAULTS['modules']['library']['enabled'])) STUDENT_CARDS_MODULE_ENABLED = _TenantAwareBool('student_cards', _get(_conf, ['modules', 'student_cards', 'enabled'], DEFAULTS['modules']['student_cards']['enabled'])) +MAIL_ADD_ON_ENABLED = _TenantAwareBool('mail', _get(_conf, ['email', 'enabled'], False)) def _match_inventory(path): if not path: return False @@ -297,11 +298,16 @@ def _match_student_cards(path): if not path: return False return path.startswith(('/student_cards')) +def _match_mail(path): + if not path: return False + return path.startswith(('/')) + # Register core modules into the pipeline MODULES.register('inventory', INVENTORY_MODULE_ENABLED, _match_inventory) MODULES.register('terminplan', TERMINPLAN_MODULE_ENABLED, _match_terminplan) MODULES.register('library', LIBRARY_MODULE_ENABLED, _match_library) MODULES.register('student_cards', STUDENT_CARDS_MODULE_ENABLED, _match_student_cards) +MODULES.register('mail', MAIL_ADD_ON_ENABLED, _match_mail) STUDENT_DEFAULT_BORROW_DAYS = int(_get(_conf, ['modules', 'student_cards', 'default_borrow_days'], DEFAULTS['modules']['student_cards']['default_borrow_days'])) STUDENT_MAX_BORROW_DAYS = int(_get(_conf, ["modules", "student_cards", "max_borrow_days"], DEFAULTS["modules"]["student_cards"]["max_borrow_days"])) diff --git a/Web/modules/emailservice/email.py b/Web/modules/emailservice/email.py index 699aa9c..dc7d488 100644 --- a/Web/modules/emailservice/email.py +++ b/Web/modules/emailservice/email.py @@ -1,51 +1,98 @@ -from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart -from modules.module_registry import ModuleRegistry as mr +from email.mime.text import MIMEText import smtplib +import time import Web.modules.database.settings as cfg def _build_smtp_client(): - smtp = smtplib.SMTP(cfg.EMAIL_SMTP_HOST, cfg.EMAIL_SMTP_PORT, timeout=cfg.EMAIL_TIMEOUT_SECONDS) + smtp = smtplib.SMTP( + cfg.EMAIL_SMTP_HOST, + cfg.EMAIL_SMTP_PORT, + timeout=cfg.EMAIL_TIMEOUT_SECONDS, + ) smtp.ehlo() if cfg.EMAIL_USE_TLS: smtp.starttls() smtp.ehlo() if cfg.EMAIL_USERNAME: - smtp.login(cfg.EMAIL_USERNAME, cfg.EMAIL_PASSWORD or '') + smtp.login(cfg.EMAIL_USERNAME, cfg.EMAIL_PASSWORD or "") return smtp -def send(email: list, subject: str, note: str, sender: str) -> bool: - """ - Sends the email with the link to the Clients - Input: - - email: Email list of all the addresses to send the link to ["","",""] - - subject: Subject of the email - - note: Note that is send with the Emails +def send(email: list | str, subject: str, note: str, sender: str) -> bool: + """Sends the email with the link to the Clients.""" + if not cfg.MODULES.is_enabled("mail"): + print("Debug: Module not enabled") + return False + + if isinstance(email, str): + email = [email] + + body_message = note + + HTML_SIGNATURE = f""" +
|
+ Mit freundlichen Grüßen +Automatisierter Email Verteiler für die Schule: {cfg.get_school_info().get("name")} Invario UG |
+
{body_message}
+