# Give an account an extra address

`POST https://api.mailmasker.org/api/v1/domains/mail-aliases`

Route an address, or a whole domain, to an account, which may also send from it.

- Who can use it: Site admins
- Area: Domains and DNS
- Answers 201 Created when it works
- Page: https://developer.mailmasker.org/alias-add

Mail to the address goes to the account, which may also send from it unless `send_enabled` is false. For a whole domain, that is every address there without a mailbox or entry of its own. Giving an address that is already routed moves it to the new account.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `source_pattern` | body | yes | An exact address, or `@` and a domain for the whole domain. | `sales@example.com` |
| `destination` | body | yes | The account it goes to. It isn't checked, so make sure it is a real one. | `you@example.com` |
| `send_enabled` | body | no | Whether the account may send from it. true if left out. |  |

## Good to know

- A domain that isn't listed yet is added, with a DNS zone but with mail off. The account can send from it, but mail sent to it arrives only once mail is turned on (Change a domain's settings).
- If that DNS zone can't be created, the answer is 502 and nothing is added.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/domains/mail-aliases' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"source_pattern":"sales@example.com","destination":"you@example.com"}'
```

Perl:

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

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

homelab-cli:

```bash
homelab-cli dns mail-aliases add sales@example.com you@example.com
```

## Response

201 Created:

```json
{
  "id": 5,
  "source_pattern": "sales@example.com",
  "destination": "you@example.com",
  "active": 1,
  "send_enabled": 1,
  "created_by": "you@example.com",
  "created_at": "2026-11-03 21:42:10.123456-06",
  "updated_at": "2026-11-03 21:42:10.123456-06"
}
```
