- Can I use this package if my hosting provider doesn’t support the PHP IMAP extension?
- Yes, this package is designed to replace the PHP IMAP extension entirely. It uses pure PHP under the hood, so it works on any Laravel deployment—including Heroku, shared hosting, or Docker environments where extensions are restricted. No server configuration changes are needed.
- How do I connect to Gmail or other IMAP servers in Laravel?
- Use the service provider to configure connections in `config/imap.php`. For Gmail, specify the host (`imap.gmail.com`), port (`993`), SSL (`true`), and credentials from environment variables. The package then integrates seamlessly with Laravel’s dependency injection, so you can inject the `ImapClient` anywhere in your app.
- Does this package support async email processing with Laravel Queues?
- Absolutely. The package is built with Laravel’s async ecosystem in mind. You can dispatch IMAP operations (e.g., fetching large folders or processing attachments) as queue jobs using Laravel Queues or Horizon. This is ideal for background tasks like email archival or bulk processing.
- What Laravel versions and PHP requirements does this package support?
- This package requires PHP 8.1+ and is fully compatible with Laravel 9, 10, and 11. It leverages modern PHP features like typed properties and enums, which align with Laravel’s latest standards. If you’re using an older Laravel version, you may need to adjust your PHP version first.
- How do I handle email attachments with this package?
- The package extracts attachments from emails, but it doesn’t automatically store them. You’ll need to implement your own logic to save attachments to local storage, S3, or another service. The API provides methods to access raw attachment data, making integration straightforward with Laravel’s filesystem or cloud storage packages.
- Is there real-time support for new emails, or do I need to poll manually?
- This package doesn’t support WebSocket-based real-time updates. Instead, it relies on polling (via `poll()`) or the IMAP `IDLE` command (via `idle()`) to check for new messages. For true real-time functionality, you’d need to combine this with a separate WebSocket solution or a cron job for periodic polling.
- Can I map IMAP messages to Eloquent models for persistence?
- Yes, the package is designed to work alongside Eloquent. You can fetch IMAP messages and map their metadata (e.g., UID, folder, subject, body) to an Eloquent model like `Email`. This allows you to store email data in your database for querying, reporting, or further processing.
- What happens if the IMAP server is unreachable or returns an error?
- The package throws an `ImapConnectionFailedException` when connection issues occur. You can catch this exception and implement custom retry logic using Laravel’s retry helper or a queue job with exponential backoff. This ensures your application remains resilient to temporary IMAP server problems.
- Are there any performance considerations for large mailboxes or bulk operations?
- The package supports lazy loading for headers and attachments, which helps manage memory usage with large mailboxes. For bulk operations, consider batching requests or using Laravel Queues to distribute the load. Always benchmark performance under your expected workload, especially if processing thousands of emails.
- What alternatives exist if I need real-time IMAP updates or built-in attachment storage?
- If you need real-time updates, consider pairing this package with a WebSocket solution like Laravel Echo or Pusher to trigger events when new emails arrive. For built-in attachment storage, you can extend the package to automatically upload attachments to S3 or another storage service using Laravel’s filesystem drivers. Alternatively, you could explore other IMAP libraries like `spatie/laravel-imap` (though it may have similar limitations).