{"record":{"id":"53385d2903d61ae0","repo":"appwrite/appwrite","slug":"message-target-not-email","errorCode":"MESSAGE_TARGET_NOT_EMAIL","errorMessage":"Message with the target ID is not an email target.","messagePattern":"Message with the target ID is not an email target\\.","errorType":"exception","errorClass":"Appwrite\\Extend\\Exception","httpStatus":400,"severity":"error","filePath":"src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php","lineNumber":117,"sourceCode":"                ? MessageStatus::PROCESSING\n                : MessageStatus::SCHEDULED;\n        }\n\n        if ($status !== MessageStatus::DRAFT && \\count($topics) === 0 && \\count($users) === 0 && \\count($targets) === 0) {\n            throw new Exception(Exception::MESSAGE_MISSING_TARGET);\n        }\n\n        $mergedTargets = \\array_merge($targets, $cc, $bcc);\n\n        if (!empty($mergedTargets)) {\n            $foundTargets = $dbForProject->find('targets', [\n                Query::equal('$id', $mergedTargets),\n                Query::equal('providerType', [MESSAGE_TYPE_EMAIL]),\n                Query::limit(\\count($mergedTargets)),\n            ]);\n\n            if (\\count($foundTargets) !== \\count($mergedTargets)) {\n                throw new Exception(Exception::MESSAGE_TARGET_NOT_EMAIL);\n            }\n\n            foreach ($foundTargets as $target) {\n                if ($target->isEmpty()) {\n                    throw new Exception(Exception::USER_TARGET_NOT_FOUND);\n                }\n            }\n        }\n\n        if (!empty($attachments)) {\n            foreach ($attachments as &$attachment) {\n                [$bucketId, $fileId] = CompoundUID::parse($attachment);\n\n                $bucket = $dbForProject->getDocument('buckets', $bucketId);\n\n                if ($bucket->isEmpty()) {\n                    throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);\n                }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/appwrite/appwrite/blob/7eab5f1970bacb06f8cce069c27b7d14a4178153/src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php#L99-L135","documentation":"Thrown when one or more of the requested target IDs does not resolve to a document of providerType email in the `targets` collection. Every ID passed in targets/cc/bcc must be an existing email target; a non-email (e.g. push) target makes the count mismatch.","triggerScenarios":"POST /v1/messaging/messages/email with a target ID that belongs to a push provider, was created for a different provider type, or was deleted (so find() returns fewer documents than requested).","commonSituations":"Reusing a target ID from a push notification flow in an email message; user switched providers so their email target was recreated with a new ID; hardcoded IDs that no longer exist.","solutions":["Fetch the user's targets (GET /v1/users/:userId/targets) and pass only IDs whose providerType is 'email'","Filter target IDs by providerType before calling createEmail","Re-check that the target still exists — deleted targets fail this check","Create an email target for the user if they only have a push target"],"exampleFix":"// before\nawait messaging.createEmail({ ..., targets: [pushTargetId] });\n// after\nconst targets = await users.listTargets(userId);\nconst emailTargetIds = targets.targets.filter(t => t.providerType === 'email').map(t => t.$id);\nawait messaging.createEmail({ ..., targets: emailTargetIds });","handlingStrategy":"validation","validationCode":"const targets = await users.listTargets(userId);\nconst emailIds = targets.targets.filter(t => t.providerType === 'email').map(t => t.$id);\nif (emailIds.length === 0) throw new Error('User has no email target');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter targets by providerType 'email' before passing them to email endpoints","Refresh target IDs after a user changes providers (old target is replaced)","Never hardcode target IDs across environments"],"tags":["messaging","targets","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"7eab5f1970bacb06f8cce069c27b7d14a4178153","analyzedAt":"2026-09-16T21:43:23.363Z","contentChangedAt":"2026-09-16T21:43:23.363Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}