# mail.enable()

Canonical URL: https://developers.iagenify.com/sdk/ref/domain/mail/enable/
Language: en

`domain.mail.enable({ subdomain?, replace? }) → Promise<Mail>`

Poses everything mail needs in one call: routing, the sender policy, the signing key and the alignment policy. On the apex, or on a subdomain when the apex already receives elsewhere.

Status: four records, one call · refuses to replace live mail · the key is reused

```javascript
await domain.mail.enable();                         // addresses at @example.com
await domain.mail.enable({ subdomain: "team" });    // at @team.example.com, apex untouched
await domain.mail.enable({ replace: true });        // replace live mail servers — deliberate
```

## Live mail is never replaced without being asked {#live-mx}

> **mail_would_replace_mx, with the current servers attached**
>
> Posing ours over a working configuration stops the customer receiving at the second it takes effect, and they find out at the first lost message. The refusal carries details.current — show it, and offer the two ways out.

```javascript
import { IaGenifyError } from "iagenify";

try {
  await domain.mail.enable();
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "mail_would_replace_mx") {
    console.log("mail currently goes to:", err.details.current);
    await domain.mail.enable({ subdomain: "team" });   // or { replace: true }
  }
}
```

Both domains most people attach already receive mail somewhere. This is the normal case, not the edge case.

## Returns {#returns}

```javascript
{
  host: "team.example.com", subdomain: "team",
  mx: [{ name, content, priority }],
  spf: "…", dkim: { selector, publicKey }, dmarc: "…",
  posed: [...], replaced: [...], failed: [...],
  dns: { mxOk, spfOk, dkimOk, dmarcOk },
  ready: true,
}
```

`failed` is the one to read: a record that did not land means mail that will not work, and calling again poses only what is missing.

## A host, not a domain {#host}

The apex and each subdomain are configured separately, each with its own records, key and policy — a policy on the apex does not cover a subdomain. Both coexist.

## Calling it twice poses nothing {#idempotent}

It writes what is missing. A second call on a configured host changes nothing, which makes it safe to run from an interface.

## What is posed, and why {#content}

- A strict sender policy — a soft one lets spoofing through.
- The sender list points at a name of ours, so the relay can change without touching a customer's zone.
- A 2048-bit signing key, with no test flag.
- An observing policy first: a strict one breaks mailing lists before anyone has looked at a report.

- [mail.status()](/sdk/ref/domain/mail/status): Reading the witnesses.
- [mail.dmarc()](/sdk/ref/domain/mail/dmarc): Hardening later.
- [api.mail](/sdk/ref/mail): Creating a mailbox on it.

```python
domain.mail.enable()                      # addresses at @example.com
domain.mail.enable(subdomain="team")      # at @team.example.com, apex untouched
domain.mail.enable(replace=True)          # replace live mail servers — deliberate
```

```python
from iagenify import IaGenifyError

try:
    domain.mail.enable()
except IaGenifyError as error:
    if error.code != "mail_would_replace_mx":
        raise
    print("mail currently goes to:", error.details["current"])
    domain.mail.enable(subdomain="team")   # or replace=True
```

```python
{
    "host": "team.example.com", "subdomain": "team",
    "mx": [{"name": ..., "content": ..., "priority": ...}],
    "spf": "…", "dkim": {"selector": ..., "publicKey": ...}, "dmarc": "…",
    "posed": [...], "replaced": [...], "failed": [...],
    "dns": {"mxOk": ..., "spfOk": ..., "dkimOk": ..., "dmarcOk": ...},
    "ready": True,
}
```
