# Set a domain's catch-all

`PUT https://api.mailmasker.org/api/v1/domains/:domain/catch-all`

Send all mail for a domain to one mailbox.

- Who can use it: Site admins, and accounts granted the domains.catchall permission
- Area: Catch-all routing
- Answers 200 OK when it works
- Page: https://developer.mailmasker.org/catch-all-set

Sets or replaces the domain's catch-all, and turns mail on for the domain, even one that was disabled. A domain the system doesn't serve yet is added, but gets no DNS zone here, so its mail must already be pointed at this system.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `domain` | path | yes | The domain whose mail to catch. | `example.org` |
| `destination` | body | yes | The mailbox it goes to. It must not be at the same domain. | `you@example.com` |
| `send_enabled` | body | no | Whether that mailbox may also send from any address at the domain. Left out, it stays as it was (off for a new catch-all). |  |

## Good to know

- The destination isn't checked here, so check it first with Check that a mailbox exists, as myaccount does.
- A destination at the same domain answers 400, and one that is itself an extra address answers 409, since either would loop.

## Examples

cURL:

```bash
curl -s -X PUT 'https://api.mailmasker.org/api/v1/domains/example.org/catch-all' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"destination":"you@example.com"}'
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->put('https://api.mailmasker.org/api/v1/domains/example.org/catch-all',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { destination => 'you@example.com' })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

There is no homelab-cli command for this yet.

## Response

200 OK:

```json
{
  "ok": true,
  "domain": "example.org",
  "destination": "you@example.com",
  "mail_enabled": true,
  "send_enabled": false
}
```
