expephalon-kumisms/core/modules/mail.py

33 lines
1.3 KiB
Python
Raw Normal View History

from core.classes.mail import SMTPMailProvider
import importlib
2020-05-21 12:54:59 +00:00
import pathlib
import os.path
import logging
from django.conf import settings
providers = { "smtp": SMTPMailProvider }
2020-05-21 12:54:59 +00:00
templates = {}
logger = logging.getLogger(__name__)
for module in settings.EXPEPHALON_MODULES + [""]:
for template in pathlib.Path(os.path.join(settings.BASE_DIR, module, "templates/mail/")).rglob("*.*"):
if os.path.isfile(template):
template_name = str(template).rsplit("templates/mail/")[-1].rsplit(".")[0]
template_format = str(template).rsplit(".")[-1].lower()
if not template_name in templates.keys():
templates[template_name] = dict()
if template_format in templates[template_name].keys():
logger.warning("Mail Template %s, that was seen at %s, was also found at %s. Using latter.",
template_name, templates[template_name][template_format], str(template))
templates[template_name][template_format] = str(template)
for module in settings.EXPEPHALON_MODULES:
try:
mom = importlib.import_module(f"{module}.mail")
for name, provider in mom.MAILPROVIDERS.items():
providers[name] = provider
except (AttributeError, ModuleNotFoundError):
continue