directorytree/imapengine-laravel
Laravel integration for ImapEngine, a PHP IMAP client that manages mailboxes without the PHP imap extension. Configure connections, access mailboxes and messages, and use a clean API to work with IMAP servers in your Laravel apps.
Strengths:
imap extension, critical for shared hosting or environments where extensions are restricted. Leverages the underlying directorytree/imapengine library, which abstracts IMAP complexity into a clean API.MailboxSynced enable reactive architectures (e.g., triggering jobs or notifications on new emails).imap:watch command supports idle (low-resource) and long-polling (fallback for restrictive environments), making it suitable for applications requiring near-real-time email processing (e.g., support tickets, lead capture).Weaknesses:
imapengine library may not match the performance of php-imap for high-throughput scenarios.imap:watch) can strain server resources if not managed (e.g., connection leaks, port exhaustion). No built-in connection pooling or load balancing.spatie/array-to-xml).Use Case Alignment:
imap extension (e.g., shared hosting, Docker).Core Features:
Mailbox::inbox()->messages()->unread()->get()).imap:watch command with configurable methods (idle or long-polling).MailboxSynced and MailboxWatchAttemptsExceeded for reactivity.php artisan imap:watch).Dependencies:
directorytree/imapengine (v1.19.0+): Core IMAP abstraction layer.imapengine.Compatibility:
illuminate/contracts version).CarbonImmutable.Technical Risks:
config or Vault). No built-in encryption for credentials in transit/storage.mailhog or dovecot).idle acceptable, or do you need long-polling due to environment restrictions (e.g., firewalls, shared hosting)?mailhog or dovecot containers)Laravel Ecosystem:
ImapEngine as a singleton, enabling dependency injection across the application.imap:watch for CLI-driven monitoring, ideal for cron jobs or Laravel Forge/Envoyer deployments.MailboxSynced (for new emails) and MailboxWatchAttemptsExceeded (for failures), enabling reactive workflows (e.g., Queues, Notifications)..env for IMAP host, port, credentials, and polling intervals, with a published config file for customization.Complementary Packages:
ProcessIncomingEmail::dispatch($email)).spatie/array-to-xml or spatie/laravel-html-email for rich email handling (e.g., HTML rendering, attachment extraction).Database Schema:
emails table for storing parsed emails:
Schema::create('emails', function (Blueprint $table) {
$table->id();
$table->string('message_id'); // Unique IMAP message ID
$table->string('mailbox'); // e.g., "INBOX"
$table->string('subject');
$table->text('body')->nullable();
$table->text('html_body')->nullable();
$table->json('headers')->nullable();
$table->json('attachments')->nullable();
$table->boolean('is_read')->default(false);
$table->boolean('is_flagged')->default(false);
$table->timestamps();
});
Evaluation Phase:
composer require directorytree/imapengine-laravel
php artisan vendor:publish --provider="DirectoryTree\ImapEngine\ImapEngineServiceProvider"
imap:watch command:
php artisan imap:watch --mailbox=INBOX --method=idle
MailboxSynced:
Event::listen(MailboxSynced::class, function ($event) {
Log::info("Synced {$event->mailbox}: " . count($event->emails) . " emails");
});
Core Integration:
ImapEngine facade in AppServiceProvider:
$this->app->singleton(ImapEngine::class, function ($app) {
return new ImapEngine(
config('imap.host'),
config('imap.port'),
config('imap.user'),
config('imap.pass'),
config('imap.ssl', true)
);
});
MailboxSynced to process emails:
public function handle(MailboxSynced $event
How can I help you explore Laravel packages today?