
# Accounts

An account is one mailbox: its IMAP settings, optional SMTP settings, and a name you choose. You can add as many as you like.

## Commands

```bash
fob-email config accounts add work --imap-host … --imap-user … --imap-pass … --smtp-host …
fob-email config accounts list               # * marks the current account
fob-email config accounts use work           # make "work" the current account
fob-email config accounts refresh work       # sign in again and update saved details (--all for every account)
fob-email config accounts remove work        # alias: rm
```

`config accounts` and `config profiles` are the same command.

- **`add`** with an existing name replaces that account. Use it to change a password or add SMTP.
- **`list`** never shows passwords. After an account has signed in once, it also shows the mailbox address and the provider fob-email detected.
- **`remove`** deletes the account from your config file only. To cut off access, also revoke the app password at your provider.

## Choosing an account per command

Commands that reach a mailbox take `--account <name>`:

```bash
fob-email emails list --account work
fob-email emails list --account personal --unseen
```

Without `--account`, fob-email uses the current account.

## Accounts from the environment

For workers, CI and containers, set `FOB_EMAIL_ACCOUNTS` to a JSON map of account names to settings. Nothing is read from or written to the config file for these accounts.

```bash
export FOB_EMAIL_ACCOUNTS='{
  "billing": {
    "imap": { "host": "imap.gmail.com", "port": 993, "user": "billing@example.com", "pass": "<app password>", "tls": true },
    "smtp": { "host": "smtp.gmail.com", "port": 465, "secure": true }
  }
}'
fob-email emails list --account billing
```

- `imap.host`, `imap.user` and `imap.pass` are required. Ports default to 993 and 465, and TLS to on.
- `smtp` is optional. Its `user` and `pass` default to the IMAP ones.
- Keep the value out of shell history and logs. Use your platform's secret store to set it.

## Which account a command uses

| You pass | fob-email uses |
| --- | --- |
| `--account work` | `work` from `FOB_EMAIL_ACCOUNTS` if it's there, otherwise `work` from the config file |
| Nothing, and `FOB_EMAIL_ACCOUNTS` is set | The **first** account in `FOB_EMAIL_ACCOUNTS` |
| Nothing | The current account from the config file, otherwise the first one in it |

So when `FOB_EMAIL_ACCOUNTS` is set, it wins over your config file's current account. Unset it, or pass `--account`, to use a config-file account.

## The config file

```yaml
# ~/.fob/fob-email/config.yml (mode 0600)
current: personal
accounts:
  personal:
    imap: { host: imap.gmail.com, port: 993, user: you@gmail.com, pass: <app password>, tls: true }
    smtp: { host: smtp.gmail.com, port: 465, user: you@gmail.com, pass: <app password>, secure: true }
    address: you@gmail.com       # filled in when the account signs in
    provider: gmail
    threadStrategy: thread-id
```

Edit it with the `config accounts` commands rather than by hand. fob-email re-applies mode 0600 every time it writes the file. To keep it somewhere else, set `FOB_EMAIL_CONFIG_DIR` to a folder; the local mirror (`sync.db`) moves with it.

`provider` and `threadStrategy` describe your server, worked out when the account signs in. `threadStrategy` decides how [threads](/docs/email/cli/reading-mail#conversations) are grouped: `thread-id` when the server provides conversation IDs (Gmail does), otherwise `reconstruct`, which follows reply headers. Run `config accounts refresh` if your provider changes.
