"""On-demand email report trigger — useful for testing SMTP config.""" from __future__ import annotations from fastapi import APIRouter, HTTPException, Request from app import auth, mailer from app.config import settings router = APIRouter() @router.post("/api/v1/report/send") async def send_report_now(request: Request): """Trigger the daily status email immediately. Admin-only because sending mail is a side effect non-admins shouldn't be able to fire.""" auth.require_admin(request) if not settings.smtp_host: raise HTTPException(status_code=503, detail="SMTP not configured (SMTP_HOST is empty)") try: await mailer.send_report_now() except Exception as exc: raise HTTPException(status_code=502, detail=f"Mail send failed: {exc}") return {"sent": True, "to": settings.smtp_to}