# Keep a key alive

An app key that goes 90 days without a signed call stops working. That protects you from keys nobody remembers, and it can surprise a product that sends rarely. One call a day prevents it.

## Check at boot and daily

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

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

// When the server starts, and once a day.
const status = await mailset.key.check();

if (status.paused) console.warn('Paused:', status.paused);
console.log('Works until', new Date(status.expiresAt));
// A mailbox key sends as its mailbox.
for (const { address, sending } of status.mailboxes)
	if (sending !== 'ready') console.warn(address, sending);
// A domain key sends as the addresses it names.
for (const { name, sending, from } of status.domains) {
	const as = from?.join(', ') ?? 'any address';
	console.log(name, 'sends as', as);
	if (sending !== 'ready') console.warn(name, sending);
}
```

```python
from datetime import datetime, timezone

from mailset import Mailset

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

# When the server starts, and once a day.
status = mailset.key.check()

if status["paused"]:
    print("Paused:", status["paused"])
ends = status["expires_at"] / 1000
until = datetime.fromtimestamp(ends, timezone.utc)
print("Works until", until)
# A mailbox key sends as its mailbox.
for box in status["mailboxes"]:
    if box["sending"] != "ready":
        print(box["address"], box["sending"])
# A domain key sends as the addresses it names.
for domain in status["domains"]:
    addresses = domain["from"]
    if addresses is None:
        sends_as = "any address"
    else:
        sends_as = ", ".join(addresses)
    print(domain["name"], "sends as", sends_as)
    if domain["sending"] != "ready":
        print(domain["name"], domain["sending"])
```

```go
import (
	"context"
	"fmt"
	"log"
	"strings"
	"time"

	mailset "mailset.app/go"
)

client, err := mailset.NewClient() // reads MAILSET_KEY
if err != nil {
	log.Fatal(err)
}
ctx := context.Background()

// When the server starts, and once a day.
status, err := client.Key.Check(ctx)
if err != nil {
	log.Fatal(err)
}

if status.Paused != nil {
	log.Println("Paused:", *status.Paused)
}
until := time.UnixMilli(status.ExpiresAt)
fmt.Println("Works until", until)
// A mailbox key sends as its mailbox.
for _, box := range status.Mailboxes {
	if box.Sending != mailset.SendingStateReady {
		log.Println(box.Address, box.Sending)
	}
}
// A domain key sends as the addresses it names.
for _, domain := range status.Domains {
	as := "any address"
	if domain.From != nil {
		as = strings.Join(domain.From, ", ")
	}
	fmt.Println(domain.Name, "sends as", as)
	if domain.Sending != mailset.SendingStateReady {
		log.Println(domain.Name, domain.Sending)
	}
}
```

```ruby
require 'mailset'

mailset = Mailset::Client.new

# When the server starts, and once a day.
status = mailset.key.check

warn "Paused: #{status.paused}" if status.paused
puts "Works until #{Time.at(status.expires_at / 1000)}"
# A mailbox key sends as its mailbox.
status.mailboxes.each do |box|
  next if box.sending == 'ready'

  warn "#{box.address}: #{box.sending}"
end
# A domain key sends as the addresses it names.
status.domains.each do |domain|
  as = domain.from&.join(', ') || 'any address'
  puts "#{domain.name} sends as #{as}"
  next if domain.sending == 'ready'

  warn "#{domain.name}: #{domain.sending}"
end
```

```php
<?php

require 'vendor/autoload.php';

use Mailset\Types\SendingState;

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

// When the server starts, and once a day.
$status = $mailset->key->check();

if ($status->paused !== null) {
    error_log("Paused: {$status->paused}");
}
$until = intdiv($status->expiresAt, 1000);
echo 'Works until ', gmdate('c', $until), PHP_EOL;

// A state this SDK doesn't know yet is text.
$text = fn ($s) => is_string($s) ? $s : $s->value;

// A mailbox key sends as its mailbox.
foreach ($status->mailboxes as $box) {
    if ($box->sending !== SendingState::Ready) {
        $state = $text($box->sending);
        error_log("{$box->address}: {$state}");
    }
}
// A domain key sends as the addresses it names.
foreach ($status->domains as $domain) {
    $as = $domain->from === null
        ? 'any address'
        : implode(', ', $domain->from);
    echo "{$domain->name} sends as {$as}", PHP_EOL;
    if ($domain->sending !== SendingState::Ready) {
        $state = $text($domain->sending);
        error_log("{$domain->name}: {$state}");
    }
}
```

```java
import app.mailset.Mailset;
import app.mailset.model.GrantDomain;
import app.mailset.model.GrantMailbox;
import app.mailset.model.KeyStatus;
import java.time.Instant;

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

// When the server starts, and once a day.
KeyStatus status = mailset.key().check();

status.paused().ifPresent(why ->
        System.err.println("Paused: " + why));
System.out.println("Works until "
        + Instant.ofEpochMilli(status.expiresAt()));
// A mailbox key sends as its mailbox.
for (GrantMailbox box : status.mailboxes())
    warn(box.address(), box.sending());
// A domain key sends as the addresses it names.
for (GrantDomain domain : status.domains()) {
    String as = domain.from()
            .map(from -> String.join(", ", from))
            .orElse("any address");
    System.out.println(
            domain.name() + " sends as " + as);
    warn(domain.name(), domain.sending());
}
```

```rust
use mailset::types::SendingState;
use mailset::Client;

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

// When the server starts, and once a day.
let status = mailset.key().check().await?;

if let Some(paused) = &status.paused {
    eprintln!("Paused: {paused}");
}
println!("Works until {} (ms)", status.expires_at);
// A mailbox key sends as its mailbox.
for b in &status.mailboxes {
    if b.sending != SendingState::Ready {
        eprintln!("{} {}", b.address, b.sending);
    }
}
// A domain key sends as the addresses it names.
for d in &status.domains {
    let from = d.from.as_ref().map(|f| f.join(", "));
    let from = from.unwrap_or("any address".into());
    println!("{} sends as {from}", d.name);
    if d.sending != SendingState::Ready {
        eprintln!("{} {}", d.name, d.sending);
    }
}
```

```bash
mailset grants current
```

Without an SDK it is `grants.current` with an empty input, the call every client in [Calling the API without an SDK](https://mailset.app/docs/authentication/http#a-client-in-your-language) makes.

## What it tells you

| Field       | What it is                                                                                                                               |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `name`      | The key's name, as approved                                                                                                              |
| `expiresAt` | When it stops, in milliseconds. Every signed call moves it 90 days out                                                                   |
| `paused`    | Why Mailset stopped this key's email, or null                                                                                            |
| `mailboxes` | A mailbox key's mailbox, the addresses it may send as, and whether its domain is `ready`. Empty for a domain key                         |
| `domains`   | A domain key's domain, whether it is `ready`, and in `from` the addresses it sends as there (null: any address). Empty for a mailbox key |

Run it when your server starts, so a revoked or mistyped key shows in your logs before a customer misses an email.

## Change what a domain key sends as

`mailset keys update <id> --from receipts@example.com --from noreply@example.com` replaces a domain key's list, and `--any-address` in its place lets it send as any address on its domain. Either asks for your passkey. Only whoever approved the key can change it, and only while they're an owner or admin of the domain's org. The key and its secret stay the same.

A send from an address the key doesn't name is refused with `forbidden`, and the message names the ones it may use: "You can't send as ceo@example.com. This key sends as receipts@example.com and noreply@example.com."

## If it is about to stop

Mailset writes to whoever approved the key 14 days and 3 days before, with a link that keeps the same key. `mailset keys renew <id>` does the same from a terminal, and `mailset keys list` shows every key with its id.

A key already past its end is gone. Make a new one with `mailset keys create`, and put it in your secret store in the old one's place.

## Watch out

- One key per kind of email. Each key is paused on its own, so sign-in codes on one key and announcements on another never stop each other.
- A key is a secret. It goes in your secret store, never in a repository or a browser.
- `mailset keys revoke <id>` ends a key at once.

---

© 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