{"record":{"id":"e52b43150a0c4918","repo":"theonedev/onedev","slug":"cannot-set-email-address-for-service-or-ai-user","errorCode":null,"errorMessage":"Cannot set email address for service or ai user","messagePattern":"Cannot set email address for service or ai user","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java","lineNumber":79,"sourceCode":"\t@Path(\"/{emailAddressId}/verified\")\n\t@GET\n\tpublic boolean isEmailAddressVerified(@PathParam(\"emailAddressId\") Long emailAddressId) {\n\t\tEmailAddress emailAddress = emailAddressService.load(emailAddressId);\n    \tif (!SecurityUtils.isAdministrator() && !emailAddress.getOwner().equals(getAuthUser())) \n\t\t\tthrow new UnauthorizedException();\n    \treturn emailAddress.isVerified();\n\t}\n\t\n\t@Api(order=200, description=\"Create new email address\")\n\t@POST\n\tpublic Long createEmailAddress(@NotNull @Valid EmailAddress emailAddress) {\n\t\tvar owner = emailAddress.getOwner();\n\t\tif (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\telse if (owner.isDisabled())\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for disabled user\");\n\t\telse if (owner.getType() != User.Type.ORDINARY)\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for service or ai user\");\n\t\telse if (User.getLoginName(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"Email address with noreply domain is not allowed\");\n\t\telse if (emailAddressService.findByValue(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"This email address is already used by another user\");\n\t\t\n\t\tif (SecurityUtils.isAdministrator()) \n\t\t\temailAddress.setVerificationCode(null);\n\t\t\n\t\temailAddressService.create(emailAddress);\n\n\t\tif (!getAuthUser().equals(owner)) \n\t\t\tauditService.audit(null, \"added email address \\\"\" + emailAddress.getValue() + \"\\\" in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", null, null);\n\t\treturn emailAddress.getId();\n\t}\n\t\n\t@Api(order=250, description=\"Set as primary email address\")\n\t@Path(\"/primary\")\n\t@POST","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java#L61-L97","documentation":"Email addresses may only be attached to ORDINARY type users in OneDev. Service accounts and AI users are non-human identities that do not use email addresses, so the endpoint rejects them with NotAcceptableException. This applies even to administrators.","triggerScenarios":"POST an EmailAddress whose owner's type is User.Type.SERVICE or AI instead of ORDINARY.","commonSituations":"Automation accidentally targeting a service account; scripting that iterates all users including service/AI users; confusing service accounts with regular robot user accounts.","solutions":["Target an ORDINARY user account instead of a service or AI user","Remove service/AI users from the provisioning loop in scripts","Create a dedicated ordinary user if an email-bearing identity is genuinely needed"],"exampleFix":"// before\nfor (User u : users) createAddress(u); // includes service users\n// after\nfor (User u : users) if (u.getType() == User.Type.ORDINARY) createAddress(u);","handlingStrategy":"validation","validationCode":"if (owner.getType() != User.Type.ORDINARY) skip;","typeGuard":"boolean ordinary = owner != null && owner.getType() == User.Type.ORDINARY;","tryCatchPattern":"try { createEmailAddress(ea); } catch (NotAcceptableException e) { /* service/AI user: use ordinary account */ }","preventionTips":["Only target ORDINARY users in email provisioning","Exclude service and AI users from user-iteration scripts","Create ordinary accounts when an email identity is needed"],"tags":["rest-api","user-types","onedev"],"backgroundTag":"unsupported-operation","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}