# DNS connection

Let Mailset write the records in your own DNS account.

An SDK signs every request with your key: [Authentication](https://mailset.app/docs/authentication.md). To sign one yourself, see [Calling the API without an SDK](https://mailset.app/docs/authentication/http.md).

## dns.status

Whether the org’s own Cloudflare is connected, the accounts and zones it sees, and whose token writes each domain.

`POST /v1/dns.status`

An admin or owner of the org.

### Parameters

It takes no input: send an empty object.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.

### Returns

`data` is an object with:

- `available` (boolean): Whether connecting Cloudflare is offered.
- `connection` (nullable object)
  - `provider` (enum): Always `cloudflare`.
  - `state` (enum): `broken`: Cloudflare refused the grant, so records go in by hand until it’s connected again. One of `connected`, `broken`.
  - `problem` (nullable string): Why it broke, or what last went wrong with it.
  - `connectedBy` (nullable string): Who connected it.
  - `connectedAt` (number)
  - `refreshedAt` (nullable number): When Mailset last renewed its access. Null: never needed to.
  - `expiresAt` (nullable number): When the access token runs out. Null: Cloudflare didn’t say.
  - `scopes` (array of strings)
- `accounts` (array of objects): The Cloudflare accounts the grant reaches, by the zones it sees.
  - `id` (string)
  - `name` (string)
- `zones` (array of strings): The zones the grant sees, by name.
- `moreZones` (boolean): The grant sees more zones than listed.
- `domains` (array of objects): Each of the org’s domains, and whose token writes its records.
  - `name` (string)
  - `zone` (nullable string): The zone the domain is in, when its nameservers answer.
  - `writer` (enum): One of `org`, `mailset`, `by_hand`.
- `problem` (nullable string): Why the zones couldn’t be read just now.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.dns.status();
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.dns.status()
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.DNS.Status(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.dns.status
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->dns->status();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.DnsStatus;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

DnsStatus answer = mailset.dns().status();
System.out.println(answer);
```

Rust:

```rust
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.dns().status().await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/dns.status \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset dns status
```

### Response

```json
{
  "ok": true,
  "data": {
    "available": true,
    "connection": {
      "provider": "cloudflare",
      "state": "connected",
      "problem": "text",
      "connectedBy": "text",
      "connectedAt": 1796048940000,
      "refreshedAt": 1796048940000,
      "expiresAt": 1796048940000,
      "scopes": [
        "text"
      ]
    },
    "accounts": [
      {
        "id": "out_3f9a1c0e7b2d",
        "name": "Acme API"
      }
    ],
    "zones": [
      "text"
    ],
    "moreZones": true,
    "domains": [
      {
        "name": "Acme API",
        "zone": "text",
        "writer": "org"
      }
    ],
    "problem": "text"
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/dns#dns-status)

## dns.connect

Let Mailset write your domains’ DNS records in your own Cloudflare: cloudflare (gives a Mailset page to open, signed in).

`POST /v1/dns.connect`

An admin or owner of the org.

### Parameters

- `provider` (enum, required): The DNS provider to connect: `cloudflare`. Always `cloudflare`.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.

### Returns

`data` is an object with:

- `url` (string): A Mailset page to open, signed in, that starts the connection.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.dns.connect({
	provider: "cloudflare",
});
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.dns.connect({"provider": "cloudflare"})
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.DNSConnectParams{
		Provider: mailset.DNSProviderCloudflare,
	}
	answer, err := client.DNS.Connect(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.dns.connect(provider: 'cloudflare')
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->dns->connect([
    'provider' => 'cloudflare',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.DnsConnectParams;
import app.mailset.model.DnsConnectResult;
import app.mailset.model.DnsProvider;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

var params = DnsConnectParams.builder()
        .provider(DnsProvider.CLOUDFLARE)
        .build();
DnsConnectResult answer = mailset.dns().connect(params);
System.out.println(answer);
```

Rust:

```rust
use mailset::types::{DnsConnectParams, DnsProvider};

// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .dns()
    .connect(DnsConnectParams {
        provider: DnsProvider::Cloudflare,
    })
    .await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/dns.connect \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"provider":"cloudflare"},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset dns connect cloudflare
```

### Response

```json
{
  "ok": true,
  "data": {
    "url": "https://hooks.example.com/mailset"
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/dns#dns-connect)

## dns.disconnect

End Mailset’s access to your Cloudflare at Cloudflare, and go back to adding records by hand.

`POST /v1/dns.disconnect`

An admin or owner of the org. It can stop for a passkey approval.

### Parameters

It takes no input: send an empty object.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.
- `approval` (string, optional): An approval’s id, once someone approved it with their passkey. Without one, the answer is `step_up_required` and names what to approve.

### Returns

`data` is an object with:

- `disconnected` (boolean)
- `revoked` (boolean): Cloudflare was told. False: Cloudflare connect isn’t set up here, so end it there too.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.dns.disconnect();
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.dns.disconnect()
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.DNS.Disconnect(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.dns.disconnect
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->dns->disconnect();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.DnsDisconnectResult;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

DnsDisconnectResult answer = mailset.dns().disconnect();
System.out.println(answer);
```

Rust:

```rust
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.dns().disconnect().await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/dns.disconnect \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset dns disconnect
```

### Response

```json
{
  "ok": true,
  "data": {
    "disconnected": true,
    "revoked": true
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/dns#dns-disconnect)

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content