diff --git a/backend/app/api/routes/auth.py b/backend/app/api/routes/auth.py index 5ef012478..0db302346 100644 --- a/backend/app/api/routes/auth.py +++ b/backend/app/api/routes/auth.py @@ -415,21 +415,15 @@ async def test_smtp_connection( current_user: User | None = RequirePermissionIfAuthEnabled(Permission.SETTINGS_UPDATE), db: AsyncSession = Depends(get_db), ): - """Test SMTP connection with provided settings (admin only when auth enabled).""" + """Test SMTP connection using saved settings (admin only when auth enabled).""" import logging logger = logging.getLogger(__name__) try: - smtp_settings = SMTPSettings( - smtp_host=test_request.smtp_host, - smtp_port=test_request.smtp_port, - smtp_username=test_request.smtp_username, - smtp_password=test_request.smtp_password, - smtp_security=test_request.smtp_security, - smtp_auth_enabled=test_request.smtp_auth_enabled, - smtp_from_email=test_request.smtp_from_email, - ) + smtp_settings = await get_smtp_settings(db) + if not smtp_settings: + return TestSMTPResponse(success=False, message="SMTP settings not configured. Save SMTP settings first.") # Send test email send_email( diff --git a/backend/app/schemas/auth.py b/backend/app/schemas/auth.py index e0d6eb2ca..0e70a5df3 100644 --- a/backend/app/schemas/auth.py +++ b/backend/app/schemas/auth.py @@ -100,16 +100,7 @@ class SMTPSettings(BaseModel): class TestSMTPRequest(BaseModel): - smtp_host: str - smtp_port: int - smtp_username: str | None = None # Optional when auth is disabled - smtp_password: str | None = None # Optional when auth is disabled - smtp_security: str = "starttls" # 'starttls', 'ssl', 'none' - smtp_auth_enabled: bool = True - smtp_from_email: str test_recipient: str - # Deprecated field for backward compatibility - smtp_use_tls: bool | None = None class TestSMTPResponse(BaseModel): diff --git a/backend/tests/integration/test_advanced_auth_api.py b/backend/tests/integration/test_advanced_auth_api.py index a270f5591..094901556 100644 --- a/backend/tests/integration/test_advanced_auth_api.py +++ b/backend/tests/integration/test_advanced_auth_api.py @@ -120,12 +120,17 @@ class TestSMTPConfigAPI: @pytest.mark.integration async def test_test_smtp_connection(self, async_client: AsyncClient, admin_token: str): """POST /auth/smtp/test with mocked send_email returns success.""" + await async_client.post( + "/api/v1/auth/smtp", + headers={"Authorization": f"Bearer {admin_token}"}, + json=SMTP_DATA, + ) + with patch("backend.app.api.routes.auth.send_email"): response = await async_client.post( "/api/v1/auth/smtp/test", headers={"Authorization": f"Bearer {admin_token}"}, json={ - **SMTP_DATA, "test_recipient": "recipient@test.com", }, ) diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index d1ef67496..07924aa35 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -2186,13 +2186,6 @@ export interface SMTPSettings { } export interface TestSMTPRequest { - smtp_host: string; - smtp_port: number; - smtp_username?: string; - smtp_password?: string; - smtp_security: 'starttls' | 'ssl' | 'none'; - smtp_auth_enabled: boolean; - smtp_from_email: string; test_recipient: string; } diff --git a/frontend/src/components/EmailSettings.tsx b/frontend/src/components/EmailSettings.tsx index 9bc43ade4..3b066c5db 100644 --- a/frontend/src/components/EmailSettings.tsx +++ b/frontend/src/components/EmailSettings.tsx @@ -26,7 +26,7 @@ export function EmailSettings() { const { t } = useTranslation(); const { showToast } = useToast(); const queryClient = useQueryClient(); - + const [smtpSettings, setSMTPSettings] = useState({ smtp_host: '', smtp_port: 587, @@ -144,23 +144,7 @@ export function EmailSettings() { showToast(t('settings.email.errors.enterTestEmail'), 'error'); return; } - if (!smtpSettings.smtp_host || !smtpSettings.smtp_from_email) { - showToast(t('settings.email.errors.smtpServerAndEmail'), 'error'); - return; - } - // Validate auth fields when authentication is enabled - if (smtpSettings.smtp_auth_enabled && (!smtpSettings.smtp_username || !smtpSettings.smtp_password)) { - showToast(t('settings.email.errors.usernamePasswordRequired'), 'error'); - return; - } testMutation.mutate({ - smtp_host: smtpSettings.smtp_host, - smtp_port: smtpSettings.smtp_port, - smtp_username: smtpSettings.smtp_username, - smtp_password: smtpSettings.smtp_password, - smtp_security: smtpSettings.smtp_security, - smtp_auth_enabled: smtpSettings.smtp_auth_enabled, - smtp_from_email: smtpSettings.smtp_from_email, test_recipient: testEmail, }); };