appwrite/appwrite · error · Appwrite\Extend\Exception
MESSAGE_TARGET_NOT_EMAIL
MESSAGE_TARGET_NOT_EMAIL
Error message
Message with the target ID is not an email target.
What it means
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.
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
Example fix
// before
await messaging.createEmail({ ..., targets: [pushTargetId] });
// after
const targets = await users.listTargets(userId);
const emailTargetIds = targets.targets.filter(t => t.providerType === 'email').map(t => t.$id);
await messaging.createEmail({ ..., targets: emailTargetIds }); Defensive patterns
Strategy: validation
Validate before calling
const targets = await users.listTargets(userId);
const emailIds = targets.targets.filter(t => t.providerType === 'email').map(t => t.$id);
if (emailIds.length === 0) throw new Error('User has no email target'); Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- MESSAGE_TARGET_NOT_SMS
- general_argument_invalid
- general_query_invalid
- general_query_invalid
- general_query_invalid
AI-assisted analysis of appwrite/appwrite@7eab5f1970 (2026-09-16).
Data as JSON: /api/errors/53385d2903d61ae0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php:117
? MessageStatus::PROCESSING
: MessageStatus::SCHEDULED;
}
if ($status !== MessageStatus::DRAFT && \count($topics) === 0 && \count($users) === 0 && \count($targets) === 0) {
throw new Exception(Exception::MESSAGE_MISSING_TARGET);
}
$mergedTargets = \array_merge($targets, $cc, $bcc);
if (!empty($mergedTargets)) {
$foundTargets = $dbForProject->find('targets', [
Query::equal('$id', $mergedTargets),
Query::equal('providerType', [MESSAGE_TYPE_EMAIL]),
Query::limit(\count($mergedTargets)),
]);
if (\count($foundTargets) !== \count($mergedTargets)) {
throw new Exception(Exception::MESSAGE_TARGET_NOT_EMAIL);
}
foreach ($foundTargets as $target) {
if ($target->isEmpty()) {
throw new Exception(Exception::USER_TARGET_NOT_FOUND);
}
}
}
if (!empty($attachments)) {
foreach ($attachments as &$attachment) {
[$bucketId, $fileId] = CompoundUID::parse($attachment);
$bucket = $dbForProject->getDocument('buckets', $bucketId);
if ($bucket->isEmpty()) {
throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);
}View on GitHub (pinned to 7eab5f1970)