Multi-Account Email Systems: Engineering Onboarding, Sending, and Offboarding
Managing many mailboxes is less about count than credential types, scattered account lists, and clean removal. This article walks through a six-step onboarding flow, sender-identity isolation, send-path pitfalls, and a four-asset offboarding checklist.
1. The hard part is not how many accounts you have
When a system hosts a dozen or more mailboxes, the real cost is not the number itself. Three structural problems dominate:
- Inconsistent credential types. Providers differ widely: some require app-specific passwords (often 16-character strings), some use authorization codes, some accept the login password, and some only support OAuth2. If a provider is OAuth2-only and the system cannot refresh tokens, exclude it before onboarding so you do not fight it later.
- Scattered account inventories. Account data often lives in config files, password files, script arguments, and docs. Adding an account means updating several places. Deleting one and missing a location can leave a silent failure: the config is gone, a script still runs, nothing errors, behavior is wrong.
- Offboarding is harder than onboarding. Fully removing an account means config sections, password files, script lists, and documentation. Onboarding is additive; a missed step usually means a feature never lights up. Offboarding is subtractive; a missed step is lasting hidden risk.
The rest of this article follows onboarding → runtime → offboarding, with real failure modes and fixes.
2. Onboarding: six gates for a new mailbox
Treat each new account as six steps with a clear artifact and known failure modes.
Step 1: Confirm credential type
Authentication requirements drive how password files are laid out and how config sections are written.
| Provider type | Typical credential | Notes |
|---|---|---|
| Public mailbox type A | App-specific password (often 16 characters) | Usually requires two-factor authentication before generation |
| Public mailbox type B | Authorization code | Not the same as the login password; request separately |
| Corporate domain mailbox | Login password | Some require the full email address as username |
| Some overseas providers | OAuth2 only | Exclude if the system has no token management |
The output is an account–credential-type–how-to-obtain table. All later config follows it.
Step 2: Store secrets in separate files
Split each account into two files: one for inbound auth, one for outbound. Restrict them to owner read/write (for example chmod 600). Config never contains plaintext passwords, only paths.
Illustrative structure:
accounts:- name: salesimap:host: imap.example.comport: 993tls: trueuser: sales@example.compassword_file: /etc/mailcred/sales_imap.passsmtp:host: smtp.example.comport: 465tls: trueuser: sales@example.compassword_file: /etc/mailcred/sales_smtp.pass
This decouples secrets from config: config can live in version control; password files do not. Permission boundaries stay clear.
Step 3: Write the account config section
Inbound is typically port 993 with TLS. Outbound is 465 with TLS, or 587 with STARTTLS. Folder aliases must match the provider: Sent, Sent Items, or a localized name. A wrong name can fail “sent” archival without a useful error.
Step 4: Generate a per-account config file
Extract each account from the main config into its own file and make that account the default in that file. Send mail by pointing at that file. Why this matters is in the next section.
Step 5: Update every account list in scripts
Lists are rarely in one place: main config, sync scripts, cron arguments, monitoring checks. Keep a “list of lists” of files that enumerate accounts, and tick through it on every add or delete.
Step 6: Verify connectivity and sender identity
Test inbound (fetch one message) and outbound (deliver one). Then send a test message and confirm in that account’s Sent folder that the From address is that account.
Do not skip step 6. In a multi-account setup the dangerous failure is not “cannot connect.” It is sending as A while authenticated as B: connection OK, send OK, logs green, only the recipient sees the wrong From. That is almost invisible in logs; you only catch it by checking sender identity.
3. Pitfall 1: the account switcher covers receive, not send
Many tools use an environment variable or CLI flag for “current account.” We started that way. The flag applied to receive; send fell back to the default account.
Result: outreach that should have come from the company sales mailbox went out from a personal default. No script error, no log anomaly. Recipients saw a personal address; the company name appeared only in the signature.
Fix: pin send identity in config, not at runtime
- Extract each account section from the main config.
- Generate one standalone config per account and set that account as default in it.
- On send, pass that file explicitly; do not rely on a switcher.
- Automate generation with a script so new accounts are not copied by hand.
Illustrative commands:
# Generate per-account config./gen_account_config.sh sales# Send using that account's configsendmail --config /etc/mailconf/sales.yaml --to user@example.com --body-file body.txt
Sender identity is then fixed in config and independent of runtime environment variables.
4. Pitfall 2: two failures in the send path itself
First: template send duplicated the body
A built-in “send with template” path compiled the body as template syntax. Recipients saw the body twice. The engine re-parsed special characters in non-template text. Fix: disable template compilation for plain text, or use a send path that skips the template engine.
Second: send-from-draft hung on Sent archival
A “read draft then send” flow stalled on copying to Sent. Slow networks timed out and hung the job. Send and archival were a single synchronous step; archival timeout failed the whole task. Fix: archive asynchronously, or give archival its own timeout and retry so archival failure does not undo a successful send.
Shared lesson: every extra step on the send path (template compile, copy to Sent) can fail. Decide what must be synchronous and what can be compensated later.
5. Offboarding: four classes of assets to remove
When an account leaves, clean all of:
- Config: main config sections, per-account files, overlays and aliases.
- Password files: inbound and outbound; confirm no leftover backups.
- Script inventories: sync jobs, cron, monitoring enumerations.
- Docs: credential tables, runbooks, handoff notes.
After cleanup, reverse-verify: try receive and send with the old paths and expect a clear error, not silent success. Silent success usually means something is still live.
6. Engineering checklist
- Secrets vs config: passwords only in dedicated files; config stores paths.
- Per-account send configs: pin identity in files, not runtime switches.
- Central inventory: maintain the list of files that enumerate accounts; check it on every change.
- Mandatory verification: check From on onboard; reverse-verify on offboard.
- Thin send path: separate sync-critical steps from async compensation so archival cannot take down send.
- Least privilege: password files owner-only; versioned config must not contain secrets.
Stable multi-account mail is less about a single flag on a tool than a process: onboard with a checklist, run with isolation, offboard with verification. Once that is fixed, growing from ten accounts to dozens need not grow ops cost in lockstep.
