diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php
index 9c79668e996f1b8d97696f7cdaa5bab3df23a5db..be4ba7602622a051e5802a7c4e0d622f109444da 100644
--- a/lib/Controller/AccountsController.php
+++ b/lib/Controller/AccountsController.php
@@ -194,6 +194,13 @@ class AccountsController extends Controller {
 						   string $smtpSslMode = null,
 						   string $smtpUser = null,
 						   string $smtpPassword = null): JSONResponse {
+		try {
+			// Make sure the account actually exists
+			$this->accountService->find($this->currentUserId, $id);
+		} catch (ClientException $e) {
+			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
+		}
+
 		$account = null;
 		$errorMessage = null;
 		try {