{"record":{"id":"37b8a27e19b21a94","repo":"immich-app/immich","slug":"user-not-found-37b8a2","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/notification.service.ts","lineNumber":262,"sourceCode":"      level: NotificationLevel.Info,\n      title: 'Cluster Group Request',\n      description: `${senderName} asked you to join their cluster group`,\n      data: JSON.stringify({ clusterGroupId }),\n    });\n\n    this.websocketRepository.clientSend('on_notification', userId, mapNotification(item));\n  }\n\n  @OnEvent({ name: 'SessionDelete' })\n  onSessionDelete({ sessionId }: ArgOf<'SessionDelete'>) {\n    // after the response is sent\n    setTimeout(() => this.websocketRepository.clientSend('on_session_delete', sessionId, sessionId), 500);\n  }\n\n  async sendTestEmail(id: string, dto: SystemConfigSmtpDto, tempTemplate?: string) {\n    const user = await this.userRepository.get(id, { withDeleted: false });\n    if (!user) {\n      throw new Error('User not found');\n    }\n\n    try {\n      await this.emailRepository.verifySmtp(dto.transport);\n    } catch (error) {\n      throw new BadRequestException('Failed to verify SMTP configuration', { cause: error });\n    }\n\n    const { server } = await this.getConfig({ withCache: false });\n    const { html, text } = await this.emailRepository.renderEmail({\n      template: EmailTemplate.TEST_EMAIL,\n      data: {\n        baseUrl: getExternalDomain(server),\n        displayName: user.name,\n      },\n      customTemplate: tempTemplate!,\n    });\n    const { messageId } = await this.emailRepository.sendEmail({","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/server/src/services/notification.service.ts#L244-L280","documentation":"Thrown by NotificationService.sendTestEmail when the user repository returns no (non-deleted) user for the given id. The service raises a plain Error('User not found') before attempting SMTP verification, so no test email can be prepared for a nonexistent recipient.","triggerScenarios":"Calling the test-email endpoint with a user id that does not exist or belongs to a soft-deleted user (withDeleted: false lookup).","commonSituations":"Sending a test email right after a user account was deleted; stale id cached in the admin UI from before a user was removed; id copied from another Immich instance/environment; passing the wrong id type or truncated id.","solutions":["Confirm the target user id exists and is not soft-deleted (list users via the admin API and use a current id)","Refresh the admin UI user list to drop stale ids","If the user was deleted, restore them or pick an active admin account for the test email","Check you are calling the correct Immich instance/environment"],"exampleFix":"// before\nawait api.notificationApi.sendTestEmail(deletedUserId, smtpDto); // throws 'User not found'\n// after\nconst users = await api.userApi.getAllUsers(false); // non-deleted users\nconst target = users.find(u => u.email === 'admin@example.com');\nawait api.notificationApi.sendTestEmail(target.id, smtpDto);","handlingStrategy":"validation","validationCode":"const users = await api.userApi.getAllUsers(false); // exclude deleted\nconst target = users.find(u => u.id === userId);\nif (!target) throw new Error(`User ${userId} not found or deleted; pick an active user`);","typeGuard":"function isActiveUser(user) {\n  return !!user && typeof user.id === 'string' && user.id.length > 0 && user.deletedAt == null;\n}","tryCatchPattern":"try {\n  await api.notificationApi.sendTestEmail(userId, smtpDto);\n} catch (e) {\n  if (String(e.message).includes('User not found')) {\n    console.warn(`User ${userId} missing/deleted; re-select recipient from user list`);\n  } else throw e;\n}","preventionTips":["Resolve user ids from a fresh user-list API call, not cached UI state","Exclude soft-deleted users when picking a test-email recipient","Re-fetch users after account deletions before sending test emails","Confirm you are targeting the correct Immich instance/environment"],"tags":["not-found","user","email","test-email"],"backgroundTag":"user-not-found","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}