# recovery.setAddress

Set the mailbox's recovery address.

Stores an address as PENDING and mails it an 8-character confirmation code, valid for 24 hours. A pending address is never a reset target, and any address already verified keeps working until the new one is confirmed. Requires the current password.

```ts
openemail.recovery.setAddress(
  identityId: string,
  body: RecoverySetAddressBody,
  options?: CallOptions,
): ApiPromise<RecoveryAddressPending>
```

It calls `PUT /identities/{identityId}/recovery`: [Set the mailbox's recovery address](/docs/api/credentials/put_RecoveryAddressSet) in the API reference.

## Example

```ts
const recoveryAddressPending = await openemail.recovery.setAddress(identityId, { address: 'ada@example.com', currentPassword: '…' })
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `identityId` | `string` | Mailbox identity ULID. The path's `{identityId}`. |
| `body` | [`RecoverySetAddressBody`](#recoverysetaddressbody) | The request's body. |

## Options

It takes no options of its own. Every call also takes `signal`, `timeout`, `retry` and `headers`, which say how that one call is sent ([call options](/docs/sdks/typescript/calling-methods#call-options)).

## Answer

Awaited, it is the API's JSON, [`RecoveryAddressPending`](/docs/sdks/typescript/types/recovery-address-pending). It is an [`ApiPromise`](/docs/sdks/typescript/responses): `.withResponse()` gives the same with the `Response` it came in, for its headers.

## Errors

| Status | What it means |
| --- | --- |
| `400` | validation_failed; password_required; or recovery_address_self, meaning the address reaches the mailbox it would recover, which is a closed loop |
| `401` | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge |
| `403` | invalid_password; or recovery_disabled, meaning the account's policy is admin_only |
| `404` | Mailbox not found or not accessible to this principal |
| `409` | no_password_credential: the mailbox has no password to re-prove |
| `413` | too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing |
| `429` | rate_limited: too many address changes, or too much mail to that destination |
| `503` | recovery_mail_unavailable: the confirmation code could not be sent for a reason on the platform's side (the mail binding is unconfigured, the sending service refused the message, or the directory of the mailbox's own account could not answer whether the address routes back to the mailbox), so nothing was stored and the call may be retried. Refused rather than stored, because a permanently pending address is worse than no address. A refusal that concerns the recipient's own address is deliberately indistinguishable from a sent code. Or temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description) |

A failed call rejects with a [`RequestError`](/docs/sdks/typescript/errors): its `status`, and its `code`, the API's `error`. Decide on the code: one status covers several.

## Types

### RecoverySetAddressBody

```ts
/** The body of `recovery.setAddress`. */
type RecoverySetAddressBody = {
  /** The address to send recovery mail to */
  address: string
  /** The mailbox's current password, re-proved */
  currentPassword: string
}
```

It names these types of the API, each on a page of its own: [`RecoveryAddressPending`](/docs/sdks/typescript/types/recovery-address-pending).
