Files
NexaPG/backend/app/schemas/admin_settings.py
nessi c437e72c2b
All checks were successful
PostgreSQL Compatibility Matrix / PG14 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG15 smoke (push) Successful in 8s
PostgreSQL Compatibility Matrix / PG16 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG17 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG18 smoke (push) Successful in 7s
Add customizable email templates and remove alert recipients
Replaced the fixed `alert_recipients` list with customizable subject and body templates for alerts and warnings. This allows for more flexible and dynamic email notifications using placeholder variables. Updated relevant backend and frontend components to support this feature.
2026-02-12 16:32:53 +01:00

57 lines
1.7 KiB
Python

from datetime import datetime
from pydantic import BaseModel, EmailStr, field_validator, model_validator
class EmailSettingsOut(BaseModel):
enabled: bool
smtp_host: str | None
smtp_port: int
smtp_username: str | None
from_name: str | None
from_email: EmailStr | None
use_starttls: bool
use_ssl: bool
warning_subject_template: str | None
alert_subject_template: str | None
warning_body_template: str | None
alert_body_template: str | None
has_password: bool
updated_at: datetime | None
class EmailSettingsUpdate(BaseModel):
enabled: bool = False
smtp_host: str | None = None
smtp_port: int = 587
smtp_username: str | None = None
smtp_password: str | None = None
clear_smtp_password: bool = False
from_name: str | None = None
from_email: EmailStr | None = None
use_starttls: bool = True
use_ssl: bool = False
warning_subject_template: str | None = None
alert_subject_template: str | None = None
warning_body_template: str | None = None
alert_body_template: str | None = None
@field_validator("smtp_port")
@classmethod
def validate_port(cls, value: int) -> int:
if value < 1 or value > 65535:
raise ValueError("smtp_port must be between 1 and 65535")
return value
@model_validator(mode="after")
def validate_tls_combo(self):
if self.use_starttls and self.use_ssl:
raise ValueError("use_starttls and use_ssl cannot both be true")
return self
class EmailSettingsTestRequest(BaseModel):
recipient: EmailStr
subject: str = "NexaPG test notification"
message: str = "This is a test alert notification from NexaPG."