mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-29 05:25:30 -05:00
Feature/email support (#720)
* feat(frontend): ✨ add UI for testing email configuration * feat(backend): ✨ add email service with common templates (WIP) * test(backend): ✅ add basic tests for email configuration * set defaults * add email variables Co-authored-by: Hayden <hay-kot@pm.me>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from . import admin_about, admin_group, admin_log
|
||||
from mealie.routes.routers import AdminAPIRouter
|
||||
|
||||
router = APIRouter(prefix="/admin")
|
||||
from . import admin_about, admin_email, admin_group, admin_log
|
||||
|
||||
router = AdminAPIRouter(prefix="/admin")
|
||||
|
||||
router.include_router(admin_about.router, tags=["Admin: About"])
|
||||
router.include_router(admin_log.router, tags=["Admin: Log"])
|
||||
router.include_router(admin_group.router, tags=["Admin: Group"])
|
||||
router.include_router(admin_email.router, tags=["Admin: Email"])
|
||||
|
||||
47
mealie/routes/admin/admin_email.py
Normal file
47
mealie/routes/admin/admin_email.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi_camelcase import CamelModel
|
||||
|
||||
from mealie.core.config import get_settings
|
||||
from mealie.core.root_logger import get_logger
|
||||
from mealie.services.email import EmailService
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/email")
|
||||
|
||||
|
||||
class EmailReady(CamelModel):
|
||||
ready: bool
|
||||
|
||||
|
||||
class EmailSuccess(CamelModel):
|
||||
success: bool
|
||||
error: str = None
|
||||
|
||||
|
||||
class EmailTest(CamelModel):
|
||||
email: str
|
||||
|
||||
|
||||
@router.get("", response_model=EmailReady)
|
||||
async def check_email_config():
|
||||
""" Get general application information """
|
||||
settings = get_settings()
|
||||
|
||||
return EmailReady(ready=settings.SMTP_ENABLE)
|
||||
|
||||
|
||||
@router.post("", response_model=EmailSuccess)
|
||||
async def send_test_email(data: EmailTest):
|
||||
print(data)
|
||||
service = EmailService()
|
||||
status = False
|
||||
error = None
|
||||
|
||||
try:
|
||||
status = service.send_test_email(data.email)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error = str(e)
|
||||
|
||||
return EmailSuccess(success=status, error=error)
|
||||
Reference in New Issue
Block a user