Download the PHP package baraja-core/doctrine-mail-message without Composer
On this page you can find all versions of the php package baraja-core/doctrine-mail-message. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baraja-core/doctrine-mail-message
More information about baraja-core/doctrine-mail-message
Files in baraja-core/doctrine-mail-message
Package doctrine-mail-message
Short Description Converter Mail message to Doctrine entity.
License
Homepage https://github.com/baraja-core/doctrine-mail-message
Informations about the package doctrine-mail-message
Doctrine Mail Message
A robust PHP library that provides bidirectional conversion between Nette Mail messages and Doctrine entities. This package allows you to persist email messages in a database, enabling email queuing, logging, retry mechanisms, and comprehensive email history tracking.
β¨ Key Features
- Bidirectional Conversion - Seamlessly convert
Nette\Mail\Messageto Doctrine entity and back - Full Email Support - Handles all standard email fields: From, To, CC, BCC, Reply-To, Return-Path, Priority
- Attachment Management - Automatic serialization and storage of file attachments with content-hash based deduplication
- Tracking Support - Automatic injection of pair tokens for email tracking and pairing
- Nette Integration - First-class support for Nette Framework via DI extension
- Type Safety - Full PHP 8.0+ type declarations with PHPStan level 9 verification
ποΈ Architecture Overview
The library follows a clean, service-oriented architecture with clear separation of concerns:
π§© Components
DoctrineMessage Entity
The core Doctrine entity (DoctrineMessage) maps to the core__email_message database table and stores:
| Field | Type | Description |
|---|---|---|
id |
integer | Auto-generated primary key |
from |
string | Sender email address |
to |
string | Primary recipient |
subject |
string | Email subject line |
htmlBody |
text (nullable) | HTML content of the email |
textBody |
text (nullable) | Plain text content |
cc |
json | Array of CC recipients |
bcc |
json | Array of BCC recipients |
replyTo |
json | Array of Reply-To addresses |
returnPath |
string (nullable) | Return path for bounces |
priority |
smallint | Email priority (default: normal) |
attachments |
json | Attachment metadata array |
MessageEntity Service
The main service class responsible for:
- Converting
Nette\Mail\Messageobjects toDoctrineMessageentities viatoEntity() - Converting
DoctrineMessageentities back toNette\Mail\MessageviatoMessage() - Managing attachment serialization/deserialization
- Automatic entity persistence during conversion
Helpers
A static utility class providing:
formatHeader()- Formats email headers from various array formats to string representationgetFileNameByContentDisposition()- Extracts filename from Content-Disposition headerprocessHtmlMail()- Injects tracking pair tokens into HTML email body
DI Extension
The DoctrineMailMessageExtension provides automatic integration with Nette Framework:
- Registers entity paths for Doctrine ORM annotation discovery
- Creates attachment storage directory in temp path
- Registers
MessageEntityas a service
π¦ Installation
It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.
To install, simply use the command:
You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.
Requirements
- PHP 8.0 or higher
- Doctrine ORM 2.7+
- Doctrine DBAL 3.2+
- Nette Framework 3.0+ (for DI integration)
βοΈ Configuration
Nette Framework Integration
Register the extension in your NEON configuration file:
The extension will automatically:
- Register the entity path for Doctrine annotations
- Create the
emailer-attachmentsdirectory in your temp folder - Register the
MessageEntityservice in the DI container
Manual Configuration
If not using Nette Framework, create the service manually:
π Basic Usage
Converting Mail Message to Entity
Converting Entity Back to Mail Message
Working with Attachments
Attachments are automatically handled during conversion:
Attachment files are stored in the configured temp directory with content-hash based naming for deduplication.
Handling CC, BCC, and Reply-To
Email Priority
Cleaning Up Attachment Storage
After successfully sending an email or when no longer needed:
Custom Attachment Directory Mode
π Email Tracking
The library automatically injects a hidden tracking token into HTML emails when converting from entity to message:
This token contains the message ID and date, enabling:
- Email open tracking (when combined with tracking pixel)
- Pairing sent emails with responses
- Email delivery verification
π Database Schema
The entity creates the following table structure:
β οΈ Error Handling
The library provides clear error messages for common issues:
- Missing From Address: Triggers error in web context, throws exception in CLI
- Missing Recipient: Triggers warning for potential issues
- Invalid Attachment Path: Throws
RuntimeExceptionor logs via PSR-3 logger - Missing Temp Directory: Throws
RuntimeExceptionwith configuration hints
π§ͺ Testing
Run static analysis:
π€ Author
Jan BarΓ‘Ε‘ek
- Website: https://baraja.cz
- GitHub: https://github.com/baraja-core
π License
baraja-core/doctrine-mail-message is licensed under the MIT license. See the LICENSE file for more details.
All versions of doctrine-mail-message with dependencies
baraja-core/url Version ^1.1
nette/di Version ^3.0
nette/mail Version ^3.0 || ^4.0
nette/utils Version ^3.0 || ^4.0
doctrine/orm Version ^2.7
doctrine/dbal Version ^3.2