Overview
The Email Marketing plugin adds a complete campaign management system to your Codapult project. Your users can build subscriber lists, create audience segments with flexible conditions, send broadcast campaigns with scheduling, and track opens and clicks — plus generate subject lines and email content with AI.
Package: @codapult/plugin-email-marketing · Price: $39 (one-time)
Install with:
npx @codapult/cli plugins add @codapult/plugin-email-marketing
Features
Subscriber Lists & Contacts
Manage subscribers across multiple lists:
- Contact management — CRUD operations on subscriber records with email, name, status, and metadata
- Status tracking — contacts can be subscribed, unsubscribed, bounced, or cleaned
- Source tracking — record how each contact was added (import, signup, API, manual)
- Bulk import — CSV upload for importing large contact lists
- Auto-sync — new users who sign up are automatically added as marketing contacts (via
onUserCreatedhook) - Multiple lists — create separate mailing lists per product, audience, or purpose
- Default list — designate one list as the default for new contacts
Audience Segmentation
Build dynamic segments with rule-based conditions:
- Condition builder — filter contacts by status, source, metadata fields, and custom attributes
- JSON conditions — flexible, composable filter rules stored as JSON
- Segment preview — see how many contacts match a segment before using it in a campaign
- Campaign targeting — send campaigns to a specific list or segment
Broadcast Campaigns
Create and send email campaigns:
- Template-based — compose campaigns using reusable email templates
- List or segment targeting — send to an entire list or a specific segment
- Scheduling — send immediately or schedule for a future date/time
- Campaign lifecycle — draft → scheduled → sending → sent → cancelled
- Per-campaign stats — open rate, click rate, bounce rate, and delivery metrics
- Cancel support — cancel scheduled campaigns before they send
Email Templates
Reusable HTML templates for campaigns:
- Template editor — create templates with subject line, HTML body, and optional JSON content blocks
- Clone and customize — duplicate existing templates as a starting point
- Template library — manage templates per organization
Open & Click Tracking
Automatic engagement tracking for every campaign:
- Open tracking — invisible tracking pixel inserted in emails; records when a recipient opens
- Click tracking — links in emails are automatically wrapped; records when a recipient clicks
- Per-contact analytics — see which contacts opened and clicked per campaign
- Campaign-level metrics — aggregate open rate, click rate, and unique engagement counts
- Link management — tracked links stored per campaign with click counts
Suppression & Unsubscribe
Compliance and deliverability management:
- Global suppression list — bounced, unsubscribed, and complained addresses per organization
- Automatic enforcement — suppressed addresses are excluded from all campaign sends
- Unsubscribe links — included in all campaign emails automatically
- Reason tracking — record why an address was suppressed (bounce, unsubscribe, complaint)
AI Content Tools
Generate and improve email content with AI:
- Subject line generation — generate up to 5 subject line variants for A/B testing
- Content generation — create full email body content from a brief/description
- Content improvement — improve existing email copy while maintaining brand voice
- Generation history — all AI generations are stored for reference (type, prompt, result, accepted flag)
Analytics
Campaign and organization-level reporting:
- Campaign stats — opens, clicks, bounces, deliveries per campaign
- Org overview — aggregate metrics across all campaigns
- Engagement trends — track engagement over time
Dashboard Pages
The plugin adds 6 pages under /dashboard/email/:
| Page | Path | Description |
|---|---|---|
| Contacts | /dashboard/email/contacts | Subscriber list with search and filters |
| Lists & Segments | /dashboard/email/lists | Mailing list and segment management |
| Campaigns | /dashboard/email/campaigns | Campaign list with status and metrics |
| Campaign Detail | /dashboard/email/campaigns/[id] | Single campaign with stats and send log |
| Templates | /dashboard/email/templates | Email template management |
| Analytics | /dashboard/email/analytics | Cross-campaign reporting dashboard |
API Routes
All routes are served under /api/plugins/email-marketing/. The plugin registers 35 API routes including:
GET|POST|PUT|DELETE /contacts+POST /contacts/import+POST /contacts/unsubscribe— contact managementGET|POST|PUT|DELETE /lists+POST /lists/contacts/add|remove— list managementGET|POST|PUT|DELETE /segments+GET /segments/preview— segment builderGET|POST|PUT|DELETE /templates— template managementGET|POST|PUT|DELETE /campaigns+POST /campaigns/send|schedule|cancel+GET /campaigns/stats— campaign lifecycleGET /track/open+GET /track/click— public tracking endpoints (pixel and redirect)GET|POST|DELETE /suppression— suppression list managementGET /analytics/overview— org-level metricsPOST /ai/subject-lines+POST /ai/content+POST /ai/improve— AI content generation
Database Tables
The plugin creates 10 tables prefixed with em_:
| Table | Purpose |
|---|---|
em_contact | Subscribers: email, name, status, source, metadata |
em_list | Mailing lists per org with cached contact count |
em_list_contact | Many-to-many list–contact membership |
em_segment | Named segments with JSON rule conditions |
em_template | Reusable templates: subject, HTML, optional JSON content |
em_campaign | Campaigns: targeting, schedule, status, template/list/segment |
em_send | Per-recipient send record: status, open/click timestamps |
em_campaign_link | Tracked links per campaign with click counts |
em_suppression | Suppressed addresses per org with reason |
em_ai_generation | AI generation history (type, prompt, result, accepted) |
Environment Variables
| Variable | Default | Description |
|---|---|---|
EM_FROM_EMAIL | — | Default sender email (falls back to core EMAIL_FROM) |
EM_FROM_NAME | — | Default sender display name |
EM_AI_MODEL | gpt-4o-mini | Model for AI subject lines and content |
EM_TRACKING_DOMAIN | — | Custom host for open/click tracking URLs |
EM_BATCH_SIZE | 100 | Recipients per send batch |
EM_RATE_LIMIT | 10 | Sends per second (match your email provider limits) |
Integration with Core Modules
| Module | How Email Marketing Uses It |
|---|---|
sendEmail() | Deliver campaigns via the host email adapter (Resend) |
enqueueEmail() | Queue batched, rate-limited campaign delivery |
| Vercel AI SDK | Subject line generation, content generation, improvement |
logActivity() | Audit trail for imports, sends, suppressions, AI actions |
checkOrgQuota() | Enforce emailContacts and emailSends resource limits |
onUserCreated | Auto-create marketing contact when a new user signs up |
onUserDeleted | Cleanup/detach marketing data for deleted users |