directorytree/imapengine
IMAP Engine is a Laravel-friendly PHP package for working with IMAP mailboxes. It simplifies connecting to mail servers, browsing folders, fetching and searching messages, and handling attachments with a clean, developer-focused API for email workflows.
Strengths:
ext-imap, critical for Laravel deployments on platforms like Heroku, shared hosting, or Docker environments where extensions are restricted.illuminate/collections, symfony/mime, and integrates seamlessly with Eloquent, Queues, and Horizon for async processing.Message-ID, Content-Disposition), reducing manual validation overhead.Gaps:
poll()) or idle() for new messages; lacks WebSocket or push-based updates.ImapEngine facade or ImapClient binding).Email table with uid, folder, subject, body).ext-imap, reducing deployment friction.composer require directorytree/imapengine installation.ext-imap (API differences require refactoring).poll()) sufficient?ext-imap (e.g., Heroku, shared hosting)? If not, is the extension’s simplicity worth the tradeoff?RFC822.SIZE, Message-ID) for legal holds? The library provides this out of the box.ImapConnectionFailedException, but custom retry logic (e.g., Laravel’s retry helper) may be needed.Laravel Integration:
ImapEngine\ImapClient to the container with configurable hosts/credentials.
// config/imap.php
'connections' => [
'gmail' => [
'host' => 'imap.gmail.com',
'port' => 993,
'ssl' => true,
'username' => env('IMAP_USERNAME'),
'password' => env('IMAP_PASSWORD'),
],
];
Imap facade for cleaner syntax:
use DirectoryTree\ImapEngine\Facades\Imap;
$folder = Imap::connect('gmail')->getFolder('INBOX');
class Email extends Model {
public static function syncFromImap($folderName) {
$folder = Imap::connect('gmail')->getFolder($folderName);
foreach ($folder->search() as $message) {
self::updateOrCreate([
'uid' => $message->uid(),
'folder' => $folderName,
], [
'subject' => $message->subject(),
'body' => $message->text(),
]);
}
}
}
Async Processing:
class ProcessEmailsJob implements ShouldQueue {
public function handle() {
$folder = Imap::connect('gmail')->getFolder('INBOX');
$folder->bulkQuery()->flag(\DirectoryTree\ImapEngine\Flag::Seen);
}
}
email:synced) or cron.Testing:
imapengine/imapengine-testing (if available) or mock the ImapClient interface in PHPUnit.ext-imap calls, custom parsing logic).ImapEngine.ImapEngine facades/models.ext-imap from php.ini if no longer needed.buildpacks).BODY responses).ImapConnectionFailedException to handle server-specific errors.symfony/mime (common in Laravel) and illuminate/collections.ext-imap fetch/search logic with ImapEngine queries.poll()) or idle() for real-time updates.How can I help you explore Laravel packages today?