Engineering Multi-Mailbox Onboarding, Operations, and Offboarding

    A practical guide to treating mail accounts as lifecycle-managed resources: a single registry, credential references instead of secrets in config, inbound/outbound identity isolation, dual-credential rotation, and a verifiable offboarding sequence so silent failures do not accumulate as accounts grow.

    Engineering Multi-Mailbox Onboarding, Operations, and Offboarding

    Lead with the conclusion

    When you host a dozen-plus mail accounts, the hard part is not the count. It is three operational problems. First, credential types are inconsistent: some providers require app passwords, some require authorization codes, some accept the login password, and some support only OAuth 2.0 with expensive token lifecycle work. Second, the account list is scattered—adding an account means touching config, scripts, and docs, and deleting one while missing a single location can leave a silent failure. Third, leaving is harder than joining: a clean removal usually spans config, credential files, script inventories, and documentation.

    A multi-account mail system should therefore be designed around a lifecycle: a fixed onboarding checklist, clear identity boundaries in production, a verifiable cleanup order on exit, and rotation with a transition window and rollback. The sections below follow onboarding, run, offboarding, and rotation, including corrections from real failures.

    1. Model accounts as resources, not config fragments

    From an engineering view, a mail account includes at least five kinds of data: identity, send/receive addresses, credential references, endpoints and security parameters, and folder mapping. Duplicate copies of any of these in different places create consistency bugs.

    A useful governance model:

    1. account_registry
    2. - account_id
    3. - address
    4. - credential_ref_inbound
    5. - credential_ref_outbound
    6. - inbound_endpoint / port / security
    7. - outbound_endpoint / port / security
    8. - folder_mapping
    9. - enabled
    10. - owner
    11. - rotation_due

    Config stores only credential references, never plaintext secrets. Keep a single source of truth for the account list; other scripts and docs should be generated from it or checked against it. Then add, rotate, and remove share one entry point.

    2. Onboarding: six gates for a new account

    1. Confirm credential type and auth model

    Providers differ: consumer mail often wants app passwords; some regional providers use authorization codes; domain/enterprise mail may use the login password; some vendors only support OAuth 2.0. Confirm which credential the account actually accepts, and whether third-party clients are allowed.

    If a provider is OAuth-only and the system lacks mature token refresh, expiry alerts, and permission revocation, do not put it in automated send/receive yet. Otherwise tokens expire, jobs fail silently, and logs show only auth errors that nobody notices.

    2. Store credentials in files; config holds references only

    Split inbound and outbound credentials into separate files, readable/writable only by the runtime user. Config names the files; it never contains passwords. Benefits: config can live in version control without leaking secrets; rotation replaces files only; offboarding deletes by reference.

    Example:

    1. accounts:
    2. - id: "sales"
    3. address: "<sales-address>"
    4. credential_ref_inbound: "secrets/sales/inbound"
    5. credential_ref_outbound: "secrets/sales/outbound"
    6. inbound:
    7. endpoint: "<inbound-host>"
    8. port: 993
    9. security: "tls"
    10. outbound:
    11. endpoint: "<outbound-host>"
    12. port: 465
    13. security: "tls"
    14. folders:
    15. sent: "<provider-sent-folder>"

    3. Account stanza: ports, security, and folder aliases per provider

    Inbound is typically port 993 with TLS. Outbound is often 465 with TLS, or 587 with STARTTLS. Folder aliases are not portable—“Sent” names differ. Declare folder mapping explicitly so sent copies can be verified.

    4. Generate per-account send config

    Do not rely on a global “current account.” From the registry, generate a send config per account and set that account as default in that file. Script the generation so new accounts do not depend on copy-paste.

    1. for acct in account_registry:
    2. cfg = build_runtime_config(acct, default_account=acct.id)
    3. write_secure("runtime/send/" + acct.id + ".conf", cfg)
    4. assert cfg.outbound.credential_ref == acct.credential_ref_outbound

    5. Update the script inventory from one registry

    Do not scatter account lists across scripts. Scripts should load the registry at start; if legacy scripts still hardcode lists, generate those lists from the registry. On add, check schedulers, send scripts, receive scripts, monitors, and docs.

    6. Verify connectivity and sender identity

    “It connects” is not enough. Test inbound, outbound, then send, and confirm in that account’s Sent folder that the From address is the account itself. Skip this and the dangerous failure is not a connection error: account A’s identity is used to send mail, logs are green, and only recipients see the wrong From.

    1. def verify_account(account_id):
    2. cfg = load_runtime_config(account_id)
    3. assert can_connect_inbound(cfg)
    4. assert can_connect_outbound(cfg)
    5. msg = build_test_message(from_addr=cfg.address)
    6. result = send_with_account(account_id, msg)
    7. sent_copy = read_sent_copy(cfg, result.message_id)
    8. assert sent_copy.from_addr == cfg.address

    3. Runtime: isolate receive switching from send identity

    A common wrapper uses one global “current account.” It is convenient until receive honors the switch and send falls back to the default account.

    The symptom: outreach that should leave the sales mailbox leaves the default personal mailbox. No script error, no obvious log anomaly. Recipients see a personal From with the company only in the signature.

    Fix: receive may use an account switch; send must not. Point send at a per-account config file. Assert From matches the config address before transmit; after send, audit account id and message id.

    1. def send_with_account(account_id, msg):
    2. cfg = load_send_config(account_id)
    3. assert msg.from_addr == cfg.address
    4. result = transmit(cfg, msg, connect_timeout=10, send_timeout=30)
    5. audit_log(account_id, result.message_id, result.accepted)
    6. return result

    4. Two send-path pitfalls

    First, a wrapper “send with template” path may compile the body as template syntax again, so recipients see duplicated content. Separate render from message construction; render once; check body hash or length before send.

    Second, “load draft then send” often hangs on writing a copy to Sent. A slow network times out the whole job. Decouple primary send from copy storage: timeouts and idempotent retry on the main path; copy write async or degrade to logging with later compensation. Do not block send on copy failure.

    5. Password rotation: dual credentials, then switch

    Order: write new, verify, switch, then delete old. Add the new credential while keeping the old; verify receive and send including Sent copies; point references at the new credential; watch success over a rotation window; delete the old file and update rotation records.

    Avoid deleting both at once (outage) and updating files without updating references (still on the old secret). Track rotation_due and last_rotated_at in the registry and alert on upcoming expiry.

    6. Offboarding: four asset classes, ordered cleanup

    Exit is easier to miss. At least four assets: config stanzas, credential files, script/schedule lists, and docs. Prefer disable, then delete, then verify:

    1. Set enabled=false and stop scheduled jobs.
    2. Delete or archive the per-account send config.
    3. Remove inbound stanzas and folder mapping.
    4. Delete inbound and outbound credential files.
    5. Clean script lists, monitors, and documentation.
    6. Full-text search for leftover ids, addresses, and credential paths.
    7. Watch logs for a cycle to confirm no silent retries.

    If you delete config but leave a script list, jobs may still target the removed account; swallowed failures become silent dead accounts. Offboarding is not finished when files are gone.

    7. Reusable checklist

    Onboarding: auth model, split credential files, ports and security, folder aliases, per-account send config, inventory update, two-way verification.
    Runtime: receive vs send identity isolation, From assert, post-send audit, timeouts and idempotent retry, degraded copy storage.
    Rotation: dual credentials, verify then switch, observation window, delete old, update records.
    Offboarding: stop jobs, delete config, delete secrets, clean lists, update docs, reference search, log watch.

    Stability does not scale with how many accounts you onboard. It scales with identity boundaries, a single inventory, and complete exit. Engineer those three, and a dozen accounts do not cost linearly more than a few.