{"id":22296774,"url":"https://github.com/webklex/laravel_imap_example","last_synced_at":"2025-10-13T22:31:16.962Z","repository":{"id":71428014,"uuid":"528072542","full_name":"Webklex/laravel_imap_example","owner":"Webklex","description":"This is an example application to showcase the integration of `webklex/laravel-imap`.","archived":false,"fork":false,"pushed_at":"2022-08-23T16:29:09.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T18:50:38.197Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Webklex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"webklex","custom":["https://www.buymeacoffee.com/webklex"]}},"created_at":"2022-08-23T16:22:46.000Z","updated_at":"2025-03-07T19:03:51.000Z","dependencies_parsed_at":"2023-02-22T21:00:15.122Z","dependency_job_id":null,"html_url":"https://github.com/Webklex/laravel_imap_example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Webklex/laravel_imap_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Webklex%2Flaravel_imap_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Webklex%2Flaravel_imap_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Webklex%2Flaravel_imap_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Webklex%2Flaravel_imap_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Webklex","download_url":"https://codeload.github.com/Webklex/laravel_imap_example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Webklex%2Flaravel_imap_example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017161,"owners_count":26085983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T17:47:34.604Z","updated_at":"2025-10-13T22:31:16.548Z","avatar_url":"https://github.com/Webklex.png","language":"PHP","funding_links":["https://ko-fi.com/webklex","https://www.buymeacoffee.com/webklex"],"categories":[],"sub_categories":[],"readme":"# Laravael-IMAP Example Application\n\nThis is an example application to showcase the integration of `webklex/laravel-imap`.\n\n## Table of Contents\n- [Requirements](#requirements--preconditions)\n- [Installation](#installation--setup)\n- [Usage](#usage)\n  - [Configuration](#account-setup--configuration)\n  - [Idle Command](#idle-command)\n  - [Additional](#additional-methods)\n- [Security](#security)\n- [License](#license)\n\n## Requirements \u0026 Preconditions\nIn this example I'm using a linux based system. This means the commands used below may vary slightly compared to windows.\n\nYou need to have the following installed:\n- PHP (php-mbstring \u0026 php-mcrypt)\n- Composer\n\nAdditional information can be found here: https://www.php-imap.com/installation\n\n## Installation \u0026 Setup\nStart by creating a new Laravel project. I'm going to name my \"laravel_imap_example\".\n```bash\ncomposer create-project laravel/laravel laravel_imap_example\n```\n\nNext lets install `webklex/laravel-imap`\n```bash\ncomposer require webklex/laravel-imap\n```\n\nIn order to use our own custom config, we'll need to publish it first:\n```bash\nphp artisan vendor:publish --provider=\"Webklex\\IMAP\\Providers\\LaravelServiceProvider\"\n```\nThis will create a new file `config/imap.php`. This file contains all possible package configurations.\n\n## Usage\n\n### Account setup \u0026 configuration\nTo use a default account, I'm going to add the following to my `.env` file:\n```text\nIMAP_HOST=somehost.com\nIMAP_PORT=993\nIMAP_ENCRYPTION=ssl\nIMAP_VALIDATE_CERT=true\nIMAP_USERNAME=user@example.com\nIMAP_PASSWORD=secret\nIMAP_DEFAULT_ACCOUNT=default\nIMAP_PROTOCOL=imap\n```\n\n### Idle command\nLet's assume you want to listen for new mails and execute some code if a new mail has arrived. We can realize this by using the `IDLE` command provided by the imap protocol.\n```bash\nphp artisan make:command CustomImapIdleCommand\n```\n\nThis will create a new command class inside `app/Console/Commands` called `CustomImapIdleCommand.php`. All we need is to modify it and implement the `Webklex\\IMAP\\Commands\\ImapIdleCommand` class.\n```php\n\u003c?php  \n  \nnamespace App\\Console\\Commands;  \n  \nuse Webklex\\IMAP\\Commands\\ImapIdleCommand;  \nuse Webklex\\PHPIMAP\\Message;  \n  \nclass CustomImapIdleCommand extends ImapIdleCommand {  \n  \n    /**  \n     * The name and signature of the console command.\n     *\n\t * @var string  \n     */    \n     protected $signature = 'custom_command';  \n  \n    /**  \n     * Holds the account information\n     *     \n     * @var string|array $account  \n     */  \n    protected $account = \"default\";  \n  \n    /**  \n     * Callback used for the idle command and triggered for every new received message\n     * @param Message $message  \n     */  \n    public function onNewMessage(Message $message) {  \n        $this-\u003einfo(\"New message received: \" . $message-\u003esubject);  \n    }  \n}\n```\n\n\nThis command should print `New message received: the message subject` as soon as we received a new mail. So lets test it:\n```bash\nphp artisan custom_command\n```\n\n..and sure enough, after sending an email with the subject \"test message\", it gets printed to the output:\n```bash\nNew message received: test message\n```\n\nAdditional reference for commands:\n- https://www.php-imap.com/frameworks/laravel/commands\n- https://laravel.com/docs/9.x/artisan#writing-commands\n\n### Additional methods\nThere are of course more possibilities than just idling.\nI'm going to create a new command, called \"ImapTest\":\n```bash\nphp artisan make:command ImapTest\n```\n\n```php\n\u003c?php  \n  \nnamespace App\\Console\\Commands;  \n  \nuse Illuminate\\Console\\Command;  \nuse Webklex\\IMAP\\Facades\\Client;  \n  \nclass ImapTest extends Command  \n{  \n    /**  \n     * The name and signature of the console command.\n     *\n\t * @var string  \n     */\n     protected $signature = 'imap:test';  \n  \n    /**  \n     * The console command description.\n     *\n\t * @var string  \n     */\n     protected $description = 'Command description';  \n  \n    /**  \n     * Execute the console command.\n     *\n\t * @return int  \n     */\n     public function handle() {\n        $client = Client::account(\"default\");  \n        $client-\u003econnect();  \n  \n        /** @var \\Webklex\\PHPIMAP\\Support\\FolderCollection $folders */  \n        $folders = $client-\u003egetFolders(false);  \n  \n        /** @var \\Webklex\\PHPIMAP\\Folder $folder */  \n        foreach($folders as $folder){  \n            $this-\u003einfo(\"Accessing folder: \".$folder-\u003epath);  \n  \n            $messages = $folder-\u003emessages()-\u003eall()-\u003elimit(3, 0)-\u003eget();  \n  \n            $this-\u003einfo(\"Number of messages: \".$messages-\u003ecount());  \n            \n            /** @var \\Webklex\\PHPIMAP\\Message $message */  \n            foreach ($messages as $message) {  \n                $this-\u003einfo(\"\\tMessage: \".$message-\u003emessage_id);  \n            }  \n        }\n            \n\t\treturn 0;  \n    }\n}\n```\n\nThis command will use the default account (as defined inside your `.env` and `config/imap.php`) and do the following actions:\n- Fetch all folders\n- Print the path of each found folder\n    - Fetch the first 3 messages from that folder\n    - Print the message ID of those messages\n\nIt might look something like this if executed:\n```bash\nAccessing folder: INBOX\nNumber of messages: 3\n        Message: d3a5e91963cb805cee975687d5acb1c6@swift.generated\n        Message: dfaa51a35c98a7a36dacfeb979f6bcb6@swift.generated\n        Message: e017b96972b6b9d58a0124fc8f0113cd@swift.generated\nAccessing folder: INBOX.new\nNumber of messages: 3\n        Message: 912455bb-ab24-d158-826a-6d5edf153d73@google.com\n        Message: 912455bb-ab24-d158-826a-6d5edf153d73@google.com\n        Message: 912455bb-ab24-d158-826a-6d5edf153d73@google.com\nAccessing folder: INBOX.9AL56dEMTTgUKOAz\nNumber of messages: 0\nAccessing folder: INBOX.U9PsHCvXxAffYvie\nNumber of messages: 0\nAccessing folder: INBOX.Trash\nNumber of messages: 3\n        Message: 986dd399-d437-51d4-76f7-51002b94e3a9@google.com\n        Message: de47dd45-9f60-6813-3dff-10359629a094@google.com\n        Message: 764cbf7f-87a4-9d9b-875e-bc2f98a7b212@google.com\nAccessing folder: INBOX.processing\nNumber of messages: 1\n        Message: 114dd8055b05250e4eac1a6a7abf9d5f@swift.generated\nAccessing folder: INBOX.Sent\nNumber of messages: 3\n        Message: 333da6d3-9722-105e-2e5a-448f04b5c9d6@somehost.com\n        Message: e34336cb4569918f190401d414a83c36@somehost.com\n        Message: 977e265d598d88d6243f9c69f24567e1@somehost.com\nAccessing folder: INBOX.OzDWCXKV3t241koc\nNumber of messages: 0\nAccessing folder: INBOX.5F3bIVTtBcJEqIVe\nNumber of messages: 0\nAccessing folder: INBOX.8J3rll6eOBWnTxIU\nNumber of messages: 0\nAccessing folder: INBOX.Junk\nNumber of messages: 1\n        Message: fb54d9575018517f32efe66916313b92@s5.somehost.se\nAccessing folder: INBOX.Drafts\nNumber of messages: 1\n        Message: 2e2511832ff2e6025ca4fab9ecf8d6e2@somehost.com\nAccessing folder: INBOX.test\nNumber of messages: 3\n        Message: da313e175eac0b21d9bf417266b00095@swift.generated\n        Message: da313e175eac0b21d9bf417266b00095@swift.generated\n        Message: 7bee603a843706a7505db393ff703b72@swift.generated\n```\n\n\n\n## Security\nIf you discover any security related issues, please email github@webklex.com instead of using the issue tracker.\n\n## License\nThe MIT License (MIT). Please see [License File][link-license] for more information.\n\n\n[link-license]: https://github.com/Webklex/laravel_imap_example/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebklex%2Flaravel_imap_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebklex%2Flaravel_imap_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebklex%2Flaravel_imap_example/lists"}