dsh-email:Using IMAP/SMTP to Enable DSH Agents to Read and Write Emails

Introduction

When running agents in DSH, email is often still a separate system: people have to open a client to check unread messages, or write their own scripts to poll IMAP. If you want an agent to list, read, reply, and forward mail within the same set of tools, you usually need to integrate with multiple vendors’ APIs or build an intermediary layer yourself. dsh-email uses standard IMAP/SMTP with an account password or an app-specific password, exposes mailbox capabilities through DSH’s email tool, and suits profiles of the “network tools” type that need real mailbox access without locking in a specific cloud vendor’s SDK.

What This Is

dsh-email is a community-maintained out-of-tree plugin for DSH (maintainer xuan25; repository xuan25/dsh-email; catalog page SkillHub entry). The plugin gives agents a working mailbox: through the email tool, it reads mail via standard IMAP and sends via SMTP. With proper configuration, the agent can inspect and handle email using only a password or an app-specific password provided by the service.

Current package version is 0.1.0, licensed under MIT. It depends on imapflow and nodemailer, and declares minimum peer versions for components like Cordis and dsh-agent (see the repo’s package.json).

Core Features

The following capabilities are summarized by use case, based on the project README.

Reading and Searching Mail

  • List messages, unread view, structured search.
  • When reading, you can choose not to mark the message as read (read without marking seen).

Accounts and Health Checks

  • verify: performs a live check for each configured account (IMAP login + SMTP authentication), without side effects.
  • Supports multiple accounts within a single plugin; when no account is specified, EMAIL_DEFAULT_ACCOUNT defines the default.

Sending Mail

  • Send, reply, forward, with attachments.
  • Optional SENT_FOLDER: writes a copy to the specified folder on send; if the folder is missing it can be auto-created per configuration (it will not create a folder named INBOX).

Mailbox Management

  • Create and delete folders; move messages.

Deletion and Permissions

  • Delete message and delete folder verbs (delete, delete_folder) are gated per account: default EMAIL_<N>_ALLOW_DELETE=false (fail-closed), and only effective for explicitly opted-in accounts.

New Mail Triggers (Optional)

  • Per-account resident IMAP watcher (defaults to watching INBOX; can be changed via TRIGGER_FOLDER).
  • Each new message can dispatch a new agent session, injecting a TRIGGER_PROMPT policy defined by the operator.
  • Concurrency and queue length can be capped; on queue overflow, messages remain UNSEEN and are retried.

Session Offload

  • Scans by minute; archives trigger sessions older than the account’s retention window (the retention window is only set via env: EMAIL_<N>_SESSION_RETENTION). Archives and logs live in $DSH_HOME/dsh-email/, helping control framework session storage size.

Connection Model

  • Except for the watcher on accounts with triggers enabled, all other verbs open a new connection per call (stateless verbs); the trigger watcher is the only persistent connection.

Installation and Activation

Install dsh-email into a specific DSH profile using the official command (do not construct a github:owner/repo form manually):

dsh plugin --profile <name> add dsh-email

Configuration has three layers: built-in defaults, the EMAIL_* environment block, and an optional Cordis patch layer. The plugin does not create configuration or state files under the profile directory; the only on-disk state related to the trigger plane is the retention log and archive directory for session offload (see the section above).

Environment variables are loaded at process startup; after changing env, you must restart the host for changes to take effect. Each account requires at least EMAIL_<N>_USER, EMAIL_<N>_PASS, EMAIL_<N>_IMAP_HOST, and EMAIL_<N>_SMTP_HOST; <N> is the uppercase account name, and account names must match ^[a-z][a-z0-9-]{0,31}$. Accounts missing required fields will warn at startup and be dropped, but startup itself will not fail.

A minimal example (excerpted from the README):

EMAIL_DEFAULT_ACCOUNT=local
EMAIL_LOCAL_USER=agent@local.example
EMAIL_LOCAL_PASS=<credential>
EMAIL_LOCAL_IMAP_HOST=mail.local.example
EMAIL_LOCAL_SMTP_HOST=mail.local.example
EMAIL_LOCAL_SENT_FOLDER=Sent

IMAP defaults to port 993 with secure mode tls; SMTP defaults to port 587 with secure mode starttls. TLS certificate verification is strict by default; only in tls/starttls modes does ALLOW_INSECURE_TLS=true accept untrusted or self-signed certificates.

Optional Cordis layer: in the profile’s cordis.patch.yml, the user global ~/.dsh/cordis.patch.yml, or --patch overrides, write camelCase config for plugin id dsh-email (e.g. defaultAccount, readBodyLimit, accounts map). Priority is: patch-supplied values > env > built-in defaults; the patch replaces the config section for that plugin id entirely—no deep merge. If the deployment supports live patch reload, changing the patch can trigger a plugin reload; otherwise it applies on next restart. Agents edit the patch via normal file editing; the plugin does not provide a tool to self-modify configuration, and the accounts verb only shows current values.

When enabling new mail triggers, besides EMAIL_<N>_TRIGGER_ENABLE=true, you must set EMAIL_<N>_TRIGGER_PROMPT; other options like TRIGGER_IDLE_MS, TRIGGER_MAX_CONCURRENT, TRIGGER_QUEUE_MAX, TRIGGER_PRESET, TRIGGER_REASONING_EFFORT, etc., are detailed in the README’s table.

Typical Usage (Configuration Side)

  1. Choose a profile and install the plugin: dsh plugin --profile <name> add dsh-email.
  2. For each account, set EMAIL_<N>_USER / PASS / IMAP and SMTP hosts (and ports/TLS mode if needed).
  3. For multiple accounts, set EMAIL_DEFAULT_ACCOUNT; when the agent needs to delete messages or folders, set EMAIL_<N>_ALLOW_DELETE=true only for the intended accounts.
  4. Start or restart the DSH host, then let the agent call the email tool to list, search, read, and send mail; use verify as described in the README to confirm connectivity.
  5. To “run an agent round on incoming mail”, enable TRIGGER_ENABLE on the corresponding account and write a good TRIGGER_PROMPT; to control the volume of historical trigger sessions, configure SESSION_RETENTION and the global EMAIL_OFFLOAD_BATCH (default: at most 50 sessions offloaded per sweep).

The default truncation limit for message body reading is 20000 characters (EMAIL_READ_BODY_LIMIT), adjustable via env or patch.

Use Cases and Considerations

Fits

  • You have a standard IMAP/SMTP mailbox (self-hosted or a common provider) and want agents to check unread, read bodies, reply/forward in-conversation, without maintaining a separate REST email API.
  • Multi-mailbox operations: configure multiple accounts in the same plugin, a default account plus per-account delete toggles, reducing risk of accidental deletion.
  • Optional “new mail → new agent session” automation with operator-defined prompt policies.

Note

  • The plugin runs with the permissions and environment variables of the current DSH process; PASS and app-specific passwords are highly sensitive. Before installation, read the source and the MIT license, and configure only in trusted environments.
  • The community catalog SkillHub and DeepSeek/HH (幻方) have no official affiliation; the DSH ecosystem emphasizes “everything is a plugin”, and this article introduces a community plugin’s capabilities, not an official storefront entry.
  • The trigger’s persistent connection and queue behavior affect connection counts and unseen flags on the mailbox side; validate verify and trigger parameters on a test account before enabling in production.
  • env and patch validation rules differ: unknown keys or out-of-range values in a patch can cause the plugin entry to fail loading; incomplete accounts on the env side only warn.

Conclusion

dsh-email consolidates mailbox reading and writing into DSH’s email tool: IMAP/SMTP, multiple accounts, optional incoming-mail triggers and session offload, configured primarily via EMAIL_* and augmented by Cordis patches. For further details, refer to the repository README.

  • Catalog page: https://www.skillhub.cn/plugins/xuan25/dsh-email
  • GitHub: https://github.com/xuan25/dsh-email
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye