mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-07 23:13:24 +00:00
- Remove reference to removed 'PayloadCMS Mailing Plugin initialized successfully' log - Add note explaining that plugin initializes silently on success - Clarify that absence of errors indicates successful initialization - Keep documentation aligned with actual plugin behavior - Bump version to 0.4.3
4.5 KiB
4.5 KiB
PayloadCMS Mailing Plugin - Development Guide
🚀 Zero-Setup Development with in-memory MongoDB - no database installation required!
Quick Start
# Install dependencies
npm install
# Start dev server with in-memory MongoDB
npm run dev
# Alternative: Use startup script with helpful info
npm run dev:start
# Alternative: Force memory database
npm run dev:memory
What You Get
🎯 Instant Setup
- ✅ In-memory MongoDB - no installation needed
- ✅ Example templates automatically created
- ✅ Test interface at
/mailing-test - ✅ Admin panel at
/admin - ✅ API endpoints for testing
📧 Pre-loaded Templates
- Welcome Email - User onboarding with premium features
- Order Confirmation - E-commerce receipt with items
- Password Reset - Security email with expiring link
🔧 Development Tools
- Web UI: http://localhost:3000/mailing-test
- Admin Panel: http://localhost:3000/admin
- GraphQL Playground: http://localhost:3000/api/graphql-playground
- API Endpoints:
POST /api/test-email- Send/schedule emailsPOST /api/process-outbox- Process email queue
Database Options
🚀 In-Memory (Default - Recommended)
npm run dev # Automatic
- Zero setup required
- Fast startup (5-10 seconds)
- Data resets on restart
- Perfect for development
🔗 External MongoDB
DATABASE_URI=mongodb://localhost:27017/payload-mailing npm run dev
Email Testing
MailHog (Recommended)
# Install and run MailHog
go install github.com/mailhog/MailHog@latest
MailHog
# View emails at: http://localhost:8025
Console Output
The dev setup logs emails to console if no SMTP server is available.
Development Workflow
- Start server:
npm run dev - Make changes to plugin source (
src/) - Rebuild plugin:
npm run build - Test changes in web interface or admin panel
- View results in MailHog or console
Plugin Testing
Via Web Interface
- Go to http://localhost:3000/mailing-test
- Select a template
- Fill in variables
- Send or schedule email
- Check MailHog for results
Via Admin Panel
- Go to http://localhost:3000/admin
- Navigate to Mailing > Email Templates
- View/edit templates
- Navigate to Mailing > Email Outbox
- Monitor email status
Via API
curl -X POST http://localhost:3000/api/test-email \\
-H "Content-Type: application/json" \\
-d '{
"type": "send",
"templateId": "TEMPLATE_ID",
"to": "test@example.com",
"variables": {
"firstName": "John",
"siteName": "Test App"
}
}'
Startup Messages
When you start the dev server, look for these messages:
🚀 PayloadCMS Mailing Plugin - Development Mode
==================================================
📦 Using in-memory MongoDB (no installation required)
🔧 Starting development server...
🚀 Starting MongoDB in-memory database...
✅ MongoDB in-memory database started
📊 Database URI: mongodb://***@localhost:port/payload-mailing-dev
📧 Mailing plugin configured with test transport
🎯 Test interface will be available at: /mailing-test
✅ Example email templates created successfully
Note: The plugin initializes silently on success (no "initialized successfully" message). If you see no errors, the plugin loaded correctly.
Troubleshooting
Server won't start
- Ensure port 3000 is available
- Check for Node.js version compatibility
- Run
npm installto ensure dependencies
Database issues
- In-memory database automatically handles setup
- For external MongoDB, verify
DATABASE_URIis correct - Check MongoDB is running if using external database
Email issues
- Verify MailHog is running on port 1025
- Check console logs for error messages
- Ensure template variables are correctly formatted
Plugin Development
The plugin source is in src/ directory:
src/plugin.ts- Main plugin configurationsrc/collections/- Email templates and outbox collectionssrc/services/- Mailing service with Handlebars processingsrc/jobs/- Background job processingsrc/utils/- Helper functions for developers
Make changes, rebuild with npm run build, and test!
Success Indicators
✅ Server starts without errors
✅ Admin panel loads at /admin
✅ Test interface loads at /mailing-test
✅ Templates appear in the interface
✅ Emails can be sent/scheduled
✅ Outbox shows email status
You're ready to develop and test the PayloadCMS Mailing Plugin! 🎉