Skip to content

feat: add email (IMAP/SMTP) target support#101

Merged
matthiastjong merged 15 commits into
mainfrom
feat/mail-integration
Jun 9, 2026
Merged

feat: add email (IMAP/SMTP) target support#101
matthiastjong merged 15 commits into
mainfrom
feat/mail-integration

Conversation

@matthiastjong

Copy link
Copy Markdown
Owner

Summary

  • New email target type alongside API and SSH — agents can search, read, send, draft, move, flag emails and download attachments via IMAP/SMTP
  • 8 new MCP tools: mail_search, mail_read, mail_attachment, mail_send, mail_draft, mail_folders, mail_move, mail_flag
  • mail_send requires explicit user approval (hardcoded, not via guard engine)
  • Dashboard: tabbed target list (API/SSH/Email with counts), email create form with IMAP/SMTP config, email detail page with test connection
  • Built with ImapFlow (IMAP) + Nodemailer (SMTP) + mailparser — connect-per-request, no connection pool in V1
  • New imap_smtp auth method type for email credentials
  • Bootstrap includes email field for email targets

Linear

DEA-4688

Test plan

  • Deploy and run migration (adds email column to targets)
  • Create email target via dashboard with IMAP/SMTP config
  • Add imap_smtp credentials and test connection
  • Grant token permission to email target
  • Test mail_folders via MCP — list mailbox folders
  • Test mail_search via MCP — search INBOX
  • Test mail_read via MCP — read a specific email
  • Test mail_draft via MCP — create a draft
  • Test mail_send via MCP — verify approval flow, then send
  • Verify audit logs show mail operations

🤖 Generated with Claude Code

Matthias 't Jong and others added 15 commits June 9, 2026 09:19
Design for building email access into Shellgate using ImapFlow + Nodemailer,
with new email target type, IMAP/SMTP auth, 8 MCP tools, and tabbed dashboard UI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address review findings: fix bootstrap field names (name not description),
add EmailConfig type union, explicit audit type extension, hardcoded
approval for mail_send, hooks.server.ts auth bypass, npm dependencies,
and files-to-modify checklist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
12-task plan covering schema, service, routes, MCP tools, dashboard UI,
bootstrap, and manual integration testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ail column

- Add EmailConfig type with imap/smtp sub-configs
- Extend targets.type to "api" | "ssh" | "email"
- Extend targets.config to SshConfig | EmailConfig
- Add email varchar(255) column to targets table
- Extend audit_logs.type to include "mail"
- Add imapflow and nodemailer dependencies
- Fix snapshot chain collision (0010/0011 duplicate ids)
- Generate migration 0012_happy_pet_avengers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mail field

- Import EmailConfig from schema
- Add validateEmailConfig: validates imap/smtp objects with host (required),
  port (1-65535, defaults: 993), and secure (boolean, default true)
- Extend createTarget to accept type "email", validate email config,
  require email field, and include it in insert
- Extend updateTarget to accept type "email", validate email config,
  and handle email field updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add "imap_smtp" to VALID_TYPES array
- Add imap_smtp branch in computeCredentialHint: parse JSON, display
  "IMAP/SMTP ••• {username}" when username present, fallback to
  "IMAP/SMTP credentials"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements all 9 mail service functions (listFolders, search,
getMessage, getAttachment, send, createDraft, moveMessage,
flagMessage, testConnection) with connect-per-request pattern
and proper mailbox locking. Installs mailparser for MIME parsing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add /mail/* agent-facing routes (search, getMessage, attachment, send,
draft, folders, move, flag), shared resolve helper, and hooks auth bypass.
Send route requires X-Shellgate-Approved: true, returns 202 with
approval_required payload otherwise.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…gets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replaces the flat target table with a tabbed view (API / SSH / Email)
showing per-type counts. Installs the shadcn-svelte tabs component.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tail page

Adds updateEmailConfig and testConnection server actions, a sheet for
editing IMAP/SMTP settings, and a Test Connection card showing
per-protocol IMAP/SMTP status on the target detail page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matthiastjong matthiastjong merged commit fdea1a1 into main Jun 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant