maatify / channel-delivery
Maatify Channel Delivery — Standalone async email delivery service with atomic acceptance and isolated synthetic recording; additional channels planned.
Requires
- php: ^8.4
- ext-curl: *
- ext-json: *
- ext-openssl: *
- ext-pdo: *
- ext-pdo_mysql: *
- ext-redis: *
- ext-sodium: *
- ext-zlib: *
- maatify/crypto: ^1.0
- maatify/email-delivery: ^1.3
- maatify/psr-logger: ^1.0
- maatify/shared-common: ^1.0
- php-di/php-di: ^7.1
- php-di/slim-bridge: ^3.0
- phpmailer/phpmailer: ^6.9
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
- slim/psr7: ^1.8
- slim/slim: ^4.15
- twig/twig: ^3.0
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Maatify Channel Delivery
Usage Guide · Examples · HTTP Reference · Changelog · Security · Contributing
Standalone asynchronous email delivery service with encrypted queues, atomic acceptance and isolated no-send recording. Other delivery channels are planned.
Artifact target: 2.1.1 — project release identity; HTTP API versioning is separate.
Latest Stable: v2.1.1, published on 2026-12-01 and available on Packagist. See the release guide and upgrade guide. See the tagged README for the historical Publication snapshot at preparation (2026-12-01). Security support covers both 1.x (latest v1.1.1) and 2.x. Security policy
Overview
Maatify Channel Delivery is a standalone asynchronous email delivery microservice, designed to accommodate additional channels in future releases.
It offloads delivery processing from your core applications, providing:
- Independent ingestion and worker operation
- Background delivery processing
- Retry mechanisms
- Secure payload encryption
- Controlled API ingestion
The Email channel is implemented. Acceptance confirms queue persistence; delivery is processed separately by the worker. Additional channels such as SMS, Telegram, and Push notifications are planned for future releases.
Atomic keyed acceptance and receipt lookup are available through the additive v2 HTTP API, using email-delivery 1.3.0. Follow the schema/binding rollout before enabling v2. v1 keeps its existing behavior.
The optional synthetic no-send HTTP endpoint records encrypted inert data in separate storage. It requires explicit retention and bounded cleanup; no timing-equality promise is made.
Features
-
Async Email Queue Process notifications asynchronously using background workers.
-
Encrypted Payloads Built-in
AES-256-GCMencryption for recipients and message contexts viamaatify/crypto. -
Template Rendering Uses Twig to render dynamic email templates safely.
-
Reply-To Support Optional
reply_tofield for admin notification emails — email goes to the admin, replies go to the customer. -
Robust Delivery Bounded retry/backoff handling for delivery failures.
-
API Key & IP Whitelisting Secure ingestion endpoints allowing only trusted origin servers.
-
Rate Limiting Redis-backed fixed-window request counter per API key. The existing Redis-unavailable behavior is fail-open.
-
Containerized Dependency Injection Built on Slim 4 + PHP-DI for modular and testable architecture.
Architecture
The system operates as an API ingestion layer combined with background workers.
Applications enqueue notification jobs via HTTP. Workers then process the queue and deliver messages asynchronously.
The email delivery pipeline is powered internally by the
maatify/email-delivery
library, which provides the rendering, transport abstraction,
and delivery engine.
Email Delivery Pipeline
Client Application
↓
Channel Delivery API
↓
Encrypted Queue (Database)
↓
Worker
↓
SMTP Transport
↓
Recipient
Detailed processing steps:
-
Enqueue In this legacy pipeline example, the client calls
/api/v1/email/enqueue. The additive v2 paths are described below. -
Encryption The handler delegates recipient and payload encryption/persistence to
maatify/email-delivery, usingMaatify\Crypto. -
Persistence Job stored securely in
cd_email_queue. -
Worker Polling
EmailQueueWorkerpolls pending jobs. -
Template Rendering Context is decrypted and injected into Twig templates.
-
SMTP Delivery Email is sent via
SmtpEmailTransport. IfreplyTowas set, aReply-Toheader is added so replies go to the specified address.
Requirements
- PHP 8.4+ (CI matrix includes 8.4 and 8.5). Upgrade compatibility
- InnoDB and PDO MySQL. The CI matrix includes MySQL 9.2 and MariaDB 11.4.
- Redis
- SMTP server
- Composer
Public Runtime API
| Entry point | Contract |
|---|---|
GET /health |
Service/database health; no SMTP-delivery probe |
POST /api/v1/email/enqueue |
Legacy per-call insert; 202 queued |
POST /api/v2/email/enqueue |
Atomic acceptance with stable consumer/key identity; 202 accepted |
GET /api/v2/email/receipt |
Same-key receipt recovery; 200 or point-in-time 404 |
POST /api/v2/email/synthetic |
Isolated encrypted no-send recording; 202 recorded |
| API-key / email-worker / queue-status / synthetic-purge / cache-clear CLI | Operator commands and configuration |
The HTTP reference links the complete contracts and template fields. Application classes and vendor internals are implementation details, not a PHP library API. See v2 examples for same-key recovery and no-send usage.
Related Projects
maatify/email-delivery– email delivery enginemaatify/crypto– encryption layer
Installation
A generic composer create-project maatify/channel-delivery follows the Stable channel
on Packagist. To pin 2.1.1:
composer create-project --prefer-dist --no-dev maatify/channel-delivery channel-delivery 2.1.1
cd channel-delivery
For source review or contribution, use a reviewed checkout:
git clone https://github.com/Maatify/channel-delivery.git cd channel-delivery git checkout <reviewed-commit-or-published-tag> composer install --no-dev --prefer-dist --no-interaction
Do not run the placeholder checkout literally. Use the committed project lock.
First setup includes the required .env, schema,
API key and worker steps. The HTTP document root is public/, never the repository root.
Configuration
Create the environment configuration file:
cp .env.example .env
The tables below introduce common settings. Use the complete configuration and CLI reference for branding, database session timeout, processing lease, synthetic retention and other operator settings.
Application
| Variable | Description |
|---|---|
APP_ENV |
Application environment (development / production) |
APP_NAME |
Name of the service instance |
SUPPORT_EMAIL |
Support contact email |
Database
| Variable | Description |
|---|---|
DB_HOST |
Database host |
DB_PORT |
Database port |
DB_DATABASE |
Database name |
DB_USERNAME |
Database username |
DB_PASSWORD |
Database password |
Example:
DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=channel_delivery DB_USERNAME=root DB_PASSWORD=secret
Encryption (Crypto)
Queue payloads and sensitive data are encrypted using AES-256-GCM through maatify/crypto.
| Variable | Description |
|---|---|
CRYPTO_ACTIVE_KEY_ID |
Identifier of the active encryption key |
CRYPTO_KEYS |
JSON array containing encryption keys |
CRYPTO_KEYS is empty in the example configuration. Set a private 32-byte key
using the generation and rotation procedure
before using the queue or synthetic endpoint. Keep the keys needed for retained
queue data, receipt replay and synthetic records.
SMTP
SMTP configuration used by the email delivery worker.
| Variable | Description |
|---|---|
MAIL_HOST |
SMTP server host |
MAIL_PORT |
SMTP server port |
MAIL_USERNAME |
SMTP username |
MAIL_PASSWORD |
SMTP password |
MAIL_FROM_ADDRESS |
Default sender email |
MAIL_FROM_NAME |
Sender display name |
MAIL_ENCRYPTION |
tls for STARTTLS, ssl for implicit TLS, or empty/unset for an intentionally unencrypted relay. Other values prevent SMTP initialization. |
MAIL_TIMEOUT |
SMTP timeout (seconds) |
MAIL_DEBUG_LEVEL |
SMTP debug level (0 = disabled) |
Redis
Redis is used for rate limiting.
| Variable | Description |
|---|---|
REDIS_HOST |
Redis host |
REDIS_PORT |
Redis port |
REDIS_PASSWORD |
Redis password (optional) |
REDIS_DB |
Redis database index |
RATE_LIMIT_MAX_REQUESTS |
Maximum requests allowed |
RATE_LIMIT_WINDOW_SECONDS |
Rate limit window duration |
TRUSTED_PROXIES |
Trusted proxy IPs (for X-Forwarded-For) |
Example:
REDIS_HOST=127.0.0.1 REDIS_PORT=6379 RATE_LIMIT_MAX_REQUESTS=100 RATE_LIMIT_WINDOW_SECONDS=60
Quick Examples
Customer-facing email
Enqueue a transactional email (e.g., welcome, OTP, verification) sent to the customer:
curl -X POST http://localhost:8080/api/v1/email/enqueue \ -H "Content-Type: application/json" \ -H "X-Api-Key: your_generated_api_key" \ -d '{ "entity_type": "user", "recipient": "user@example.com", "template_key": "welcome", "language": "en", "sender_type": 1, "context": { "user_name": "Ahmed", "activation_link": "https://example.com/activate?token=abc" } }'
Admin notification with Reply-To (v1.1.0+)
Enqueue an admin notification where the email goes to the admin, and replies go to the customer:
curl -X POST http://localhost:8080/api/v1/email/enqueue \ -H "Content-Type: application/json" \ -H "X-Api-Key: your_generated_api_key" \ -d '{ "entity_type": "contact_form", "recipient": "admin@example.com", "reply_to": "customer@example.com", "template_key": "admin_notification", "language": "en", "sender_type": 1, "context": { "customer_name": "Ahmed", "customer_email": "customer@example.com", "customer_message": "I need help with my account." } }'
Worker Usage
Run the email worker for a basic local setup.
php scripts/email_worker.php --batch=50 --loop --sleep=5
Run production workers under Supervisor
or systemd. The worker can reconnect before
a claim and exits with code 1 after repeated connection failures.
php scripts/email_queue_status.php alone checks the queue. For heartbeat and
recent outcome alerts, give each worker a persistent state file and pass all
those paths to the monitor.
Documentation
- Documentation Index
- Usage Guide
- 2.1.1 Upgrade Guide
- 2.1.0 Upgrade Guide
- Configuration / CLI Reference
- Atomic v2 Contract
- Synthetic Contract
- Release Qualification Checklist
- Run Worker Guide
- Send Email Guide
- API Documentation: Email Enqueue
- Basic Usage Example
License
This project is open-sourced software licensed under the MIT License.
See the LICENSE file for details.
Contributing
Use a source clone and the contribution guide. Release archives omit test infrastructure. Please follow the Code of Conduct and report vulnerabilities privately through SECURITY.md.
Author
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries