{"record":{"id":"90af48509005bab5","repo":"phacility/phabricator","slug":"this-email-address-is-already-in-use","errorCode":null,"errorMessage":"This email address is already in use.","messagePattern":"This email address is already in use\\.","errorType":"validation","errorClass":"PhabricatorApplicationTransactionValidationException","httpStatus":null,"severity":"error","filePath":"src/applications/metamta/editor/PhabricatorMetaMTAApplicationEmailEditor.php","lineNumber":165,"sourceCode":"        break;\n    }\n\n    return $errors;\n  }\n\n  protected function didCatchDuplicateKeyException(\n    PhabricatorLiskDAO $object,\n    array $xactions,\n    Exception $ex) {\n\n    $errors = array();\n    $errors[] = new PhabricatorApplicationTransactionValidationError(\n      PhabricatorMetaMTAApplicationEmailTransaction::TYPE_ADDRESS,\n      pht('Duplicate'),\n      pht('This email address is already in use.'),\n      null);\n\n    throw new PhabricatorApplicationTransactionValidationException($errors);\n  }\n\n\n}\n","sourceCodeStart":147,"sourceCodeEnd":170,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/metamta/editor/PhabricatorMetaMTAApplicationEmailEditor.php#L147-L170","documentation":"The application-email editor writes rows to the application email table, which enforces a UNIQUE key on address. MySQL raised a duplicate-key error and Lisk routed it to didCatchDuplicateKeyException(), which converts it into a PhabricatorApplicationTransactionValidationException attached to the TYPE_ADDRESS field. The address you tried to create or rename to already exists on another application email record.","triggerScenarios":"Creating a PhabricatorMetaMTAApplicationEmail (or editing one's address via the editor) to a value already owned by another record - e.g. adding differential@example.com while a Maniphest or Differential application email already uses that exact address; also two simultaneous creations of the same address.","commonSituations":"Configuring inbound addresses for multiple applications and reusing one address; migrating/importing application email config on top of existing rows; race conditions when two admins add the same address at once.","solutions":["List existing application emails first (the application's Email Addresses panel, or PhabricatorMetaMTAApplicationEmailQuery) and edit or reuse the existing record instead of creating a duplicate.","Use a unique address per application (reviews@, tasks@, commits@...).","If you genuinely need to move an address to another application, delete it from the old application first, then create it on the new one."],"exampleFix":"// before: create blindly\n$email = PhabricatorMetaMTAApplicationEmail::initializeNewEmail($viewer)\n  ->setAddress('reviews@example.com');\n$editor->applyTransactions($email, $xactions);\n\n// after: pre-check uniqueness, reuse when present\n$existing = id(new PhabricatorMetaMTAApplicationEmailQuery())\n  ->setViewer($viewer)\n  ->withAddresses(array('reviews@example.com'))\n  ->executeOne();\nif ($existing) {\n  $email = $existing; // edit instead of create\n}\n$editor->applyTransactions($email, $xactions);","handlingStrategy":"validation","validationCode":"// Pre-check address uniqueness before saving.\n$existing = id(new PhabricatorMetaMTAApplicationEmailQuery())\n  ->setViewer($viewer)\n  ->withAddresses(array($address))\n  ->executeOne();\nif ($existing && $existing->getID() != $email->getID()) {\n  // reuse $existing or pick another address\n}","typeGuard":null,"tryCatchPattern":"try {\n  $editor->applyTransactions($email, $xactions);\n} catch (PhabricatorApplicationTransactionValidationException $ex) {\n  foreach ($ex->getErrors() as $error) {\n    if ($error->getType() === PhabricatorMetaMTAApplicationEmailTransaction::TYPE_ADDRESS) {\n      // show 'address already in use' next to the address field\n    }\n  }\n}","preventionTips":["Treat inbound addresses as globally unique across applications; enforce a per-application naming convention.","When addresses come from user input or imports, pre-check with PhabricatorMetaMTAApplicationEmailQuery before save."],"tags":["phabricator","metamta","application-email","unique-constraint","validation"],"backgroundTag":"unique-constraint-violation","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}