@@ -13,27 +13,15 @@ Laravel IMAP is an easy way to integrate both the native php-imap module and an
1313into your ** Laravel** app. This enables your app to not only respond to new emails but also allows it to
1414read and parse existing mails and much more.
1515
16- > If you want to use this library outside of Laravel, please head over to [ webklex/php-imap] ( https://github.com/Webklex/php-imap )
17- > for a standalone version.
16+ Official documentation: [ php-imap.com/frameworks/laravel] ( https://www.php-imap.com/frameworks/laravel/installation )
1817
1918
2019## Table of Contents
2120- [ Documentations] ( #documentations )
22- - [ Installation] ( #installation )
23- - [ Configuration] ( #configuration )
24- - [ Usage] ( #usage )
25- - [ Basic usage example] ( #basic-usage-example )
26- - [ Facade] ( #facade )
27- - [ View examples] ( #view-examples )
28- - [ Idle] ( #idle )
29- - [ oAuth] ( #oauth )
30- - [ Events] ( #events )
31- - [ Commands] ( #commands )
32- - [ Event driven] ( #event-driven )
33- - [ Custom command] ( #custom-command )
34- - [ Service setup] ( #service-setup )
35- - [ Support] ( #support )
21+ - [ Basic usage example] ( #basic-usage-example )
3622- [ Known issues] ( #known-issues )
23+ - [ Support] ( #support )
24+ - [ Features & pull requests] ( #features--pull-requests )
3725- [ Security] ( #security )
3826- [ Credits] ( #credits )
3927- [ Supporters] ( #supporters )
@@ -42,79 +30,17 @@ read and parse existing mails and much more.
4230
4331## Documentations
4432- Legacy (< v2.0.0): [ legacy documentation] ( https://github.com/Webklex/laravel-imap/tree/1.6.2#table-of-contents )
45- - Core documentation: [ webklex/php-imap] ( https://github.com/Webklex/php-imap )
46- - Wiki: [ php-imap wiki] ( https://github.com/Webklex/php-imap/wiki )
47-
48-
49- ## Installation
50- 1.) Install the Laravel IMAP package by running the following command:
51- ``` shell
52- composer require webklex/laravel-imap
53- ```
54-
55- 1.1.) If you are getting errors or having some other issue, please follow step 1. - 1.1
56- [ here] ( https://github.com/Webklex/php-imap#installation ) .
57-
58- 1.2.) If you are having trouble with v2.0.0, please go ahead and create a new issue and perhaps
59- try the latest v1.6.2 version:
60- ``` shell
61- composer require webklex/laravel-imap:1.6.2
62- ```
63-
64- 2.) If you're using Laravel >= 5.5, package discovery will configure the service provider and ` Client ` alias out of the box.
65- Otherwise, for Laravel <= 5.4, edit your ` config/app.php ` file and:
66- - add the following to the ` providers ` array:
67- ``` php
68- Webklex\IMAP\Providers\LaravelServiceProvider::class,
69- ```
70- - add the following to the ` aliases ` array:
71- ``` php
72- 'Client' => Webklex\IMAP\Facades\Client::class,
73- ```
74-
75- 3.) Run the command below to publish the package config file [ config/imap.php] ( src/config/imap.php ) :
76- ``` shell
77- php artisan vendor:publish --provider=" Webklex\IMAP\Providers\LaravelServiceProvider"
78- ```
79-
80- ## Configuration
81- If you are planning to use a single account, you might want to add the following to
82- your ` .env ` file.
83- ```
84- IMAP_HOST=somehost.com
85- IMAP_PORT=993
86- IMAP_ENCRYPTION=ssl
87- IMAP_VALIDATE_CERT=true
88- 89- IMAP_PASSWORD=secret
90- IMAP_DEFAULT_ACCOUNT=default
91- IMAP_PROTOCOL=imap
92- ```
33+ - Core documentation: [ php-imap.com] ( https://www.php-imap.com/ )
9334
94- Please see [ webklex/php-imap#Configuration] ( https://github.com/Webklex/php-imap#configuration ) and
95- [ config/imap.php] ( src/config/imap.php ) for a detailed list of all available config options.
9635
97-
98- ## Usage
99- #### Basic usage example
36+ ## Basic usage example
10037This is a basic example, which will echo out all Mails within all imap folders
10138and will move every message into INBOX.read. Please be aware that this should not be
10239tested in real life and is only meant to gives an impression on how things work.
10340
10441``` php
10542/** @var \Webklex\PHPIMAP\Client $client */
106- $client = \Webklex\IMAP\Facades\Client::make([
107- 'host' => 'somehost.com',
108- 'port' => 993,
109- 'encryption' => 'ssl',
110- 'validate_cert' => true,
111- 'username' => 'username',
112- 'password' => 'password',
113- 'protocol' => 'imap'
114- ]);
115- /* Alternative by using the Facade
11643$client = Webklex\IMAP\Facades\Client::account('default');
117- */
11844
11945//Connect to the IMAP Server
12046$client->connect();
@@ -138,239 +64,53 @@ foreach($folders as $folder){
13864 echo $message->getHTMLBody();
13965
14066 //Move the current Message to 'INBOX.read'
141- if($message->moveToFolder ('INBOX.read') == true){
67+ if($message->move ('INBOX.read') == true){
14268 echo 'Message has ben moved';
14369 }else{
14470 echo 'Message could not be moved';
14571 }
14672 }
14773}
14874```
149- Please see [ webklex/php-imap#Table of Contents] ( https://github.com/Webklex/php-imap#table-of-contents ) for more detail
150- and further examples.
151-
152-
153- #### Facade
154- If you use the Facade [ \Webklex\IMAP\Facades\Client::class] ( src/IMAP/Facades/Client.php ) ,
155- please start by selecting an in [ config/imap.php] ( src/config/imap.php ) defined account first followed by
156- ` Client::connect() ` to establish an authenticated connection:
157-
158- ``` php
159- use Webklex\IMAP\Facades\Client;
160-
161- /** @var \Webklex\PHPIMAP\Client $client */
162- $client = Client::account('default');
163- $client->connect();
164- ```
165-
166- #### View examples
167- You can find a few blade and [ mask] ( https://github.com/Webklex/php-imap#masking ) examples under [ /examples] ( examples ) .
168-
169-
170- #### Idle
171- Every time a new message is received, the server will notify the client and return the new message.
172-
173- The callback and ` Webklex\IMAP\Events\MessageNewEvent($message) ` event get fired by every new incoming email.
174-
175- ``` php
176- $timeout = 1200;
177- /** @var \Webklex\PHPIMAP\Folder $folder */
178- $folder->idle(function($message){
179- /** @var \Webklex\PHPIMAP\Message $message */
180- dump("new message", $message->subject);
181- }, $timeout);
182- ```
183-
184- #### oAuth
185- Please take a look at [ the wiki article] ( https://github.com/Webklex/php-imap/wiki/Google-Mail---Gmail ) for gmail / google mail setup.
186-
187- Basic oAuth example:
188- ``` php
189- /** @var \Webklex\PHPIMAP\Client $client */
190- $client = \Webklex\IMAP\Facades\Client::make([
191- 'host' => 'somehost.com',
192- 'port' => 993,
193- 'encryption' => 'ssl',
194- 'validate_cert' => true,
195- 'username' => '
[email protected] ',
196- 'password' => 'ACCESS-TOKEN',
197- 'authentication' => "oauth",
198- 'protocol' => 'imap'
199- ]);
200-
201- //Connect to the IMAP Server
202- $client->connect();
203- ```
204-
205- #### Events
206- The following events are available:
207- - ` Webklex\IMAP\Events\MessageNewEvent($message) ` &mdash ; can get triggered by ` Folder::idle `
208- - ` Webklex\IMAP\Events\MessageDeletedEvent($message) ` &mdash ; triggered by ` Message::delete `
209- - ` Webklex\IMAP\Events\MessageRestoredEvent($message) ` &mdash ; triggered by ` Message::restore `
210- - ` Webklex\IMAP\Events\MessageMovedEvent($old_message, $new_message) ` &mdash ; triggered by ` Message::move `
211- - ` Webklex\IMAP\Events\MessageCopiedEvent($old_message, $new_message) ` &mdash ; triggered by ` Message::copy `
212- - ` Webklex\IMAP\Events\FlagNewEvent($flag) ` &mdash ; triggered by ` Message::setFlag `
213- - ` Webklex\IMAP\Events\FlagDeletedEvent($flag) ` &mdash ; triggered by ` Message::unsetFlag `
214- - ` Webklex\IMAP\Events\FolderNewEvent($folder) ` &mdash ; can get triggered by ` Client::createFolder `
215- - ` Webklex\IMAP\Events\FolderDeletedEvent($folder) ` &mdash ; triggered by ` Folder::delete `
216- - ` Webklex\IMAP\Events\FolderMovedEvent($old_folder, $new_folder) ` &mdash ; triggered by ` Folder::move `
217-
218- Additional integration information:
219- - https://laravel.com/docs/7.x/events#event-subscribers
220- - https://laravel.com/docs/5.2/events#event-subscribers
221- - https://github.com/Webklex/php-imap#events
222-
223-
224- # Commands
225- Let's assume you want to run the imap idle process in the background of your server to automatically handle new
226- messages. The following examples will show two major ways to archive this:
227-
228- ### Event driven
229- Start by adding the following to your ` app/Console/Kernel.php ` file:
230- ``` php
231- /**
232- * The Artisan commands provided by your application.
233- *
234- * @var array
235- */
236- protected $commands = [
237- \Webklex\IMAP\Commands\ImapIdleCommand::class,
238- ];
239- ```
240- Now register an event listener as described by [ the laravel docs] ( https://laravel.com/docs/7.x/events#event-subscribers ) .
241- If you don't use the default account, or if you want to add some of your own magic, you'll need to create a
242- custom command (see next section).
243-
244- Finally test the command by running:
245- ``` bash
246- php artisan imap:idle
247- ```
248-
249- ### Custom Command
250- Create a new file like ` app/Console/Commands/CustomImapIdleCommand.php ` and add the following:
251- ``` php
252- <?php
253- namespace App\Console\Commands;
254-
255- use Webklex\IMAP\Commands\ImapIdleCommand;
256- use Webklex\PHPIMAP\Message;
257-
258- class CustomImapIdleCommand extends ImapIdleCommand {
259-
260- /**
261- * The name and signature of the console command.
262- *
263- * @var string
264- */
265- protected $signature = 'custom_command';
266-
267- /**
268- * Holds the account information
269- *
270- * @var string|array $account
271- */
272- protected $account = "default";
273-
274- /**
275- * Callback used for the idle command and triggered for every new received message
276- * @param Message $message
277- */
278- public function onNewMessage(Message $message){
279- $this->info("New message received: ".$message->subject);
280- }
281-
282- }
283- ```
284- ..and add the following to your ` app/Console/Kernel.php ` file:
285- ``` php
286- /**
287- * The Artisan commands provided by your application.
288- *
289- * @var array
290- */
291- protected $commands = [
292- \App\Console\Commands\CustomImapIdleCommand::class,
293- ];
294- ```
295-
296- Finally test the command by running:
297- ``` bash
298- php artisan custom_command
299- ```
300-
301- ## Service setup
302- A basic systemd service can be setup by creating a service file like this:
303- ``` bash
304- nano /etc/systemd/system/imap-idle.service
305- ```
306- ..and adding:
307- ``` bash
308- [Unit]
309- Description=ImapIdle
310- After=multi-user.target
311- After=syslog.target
312- After=network-online.target
313-
314- [Service]
315- Type=simple
316-
317- User=www-data
318- Group=www-data
319-
320- WorkingDirectory=/var/www/my_project
321- ExecStart=/var/www/my_project/artisan fetch:idle
322-
323- Restart=on-failure
324- RestartSec=5s
325-
326- [Install]
327- WantedBy=multi-user.target
328- ```
329-
330- You can now test the service by running:
331- ``` bash
332- systemctl start imap-idle.service
333- systemctl status imap-idle.service
334- systemctl stop imap-idle.service
335- systemctl restart imap-idle.service
336- ```
337-
338-
339- ## Support
340- If you encounter any problems or if you find a bug, please don't hesitate to create a new
341- [ issue] ( https://github.com/Webklex/laravel-imap/issues ) .
342- However please be aware that it might take some time to get an answer.
343-
344- Off topic, rude or abusive issues will be deleted without any notice.
345-
346- If you need
** immediate
** or
** commercial
** support, feel free to send me a mail at
[email protected] .
347-
348- ##### A little notice
349- If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read
350- and people are more likely to comment and help :)
351-
352- ` ;` ;` ; php
353-
354- echo 'your php code...';
355-
356- ` ;` ;` ;
357-
358- will turn into:
359- ``` php
360- echo 'your php code...';
361- ```
362-
363- ### Features & pull requests
364- Everyone can contribute to this project. Every pull request will be considered but it can also happen to be declined.
365- To prevent unnecessary work, please consider to create a [ feature issue] ( https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md )
366- first, if you're planning to do bigger changes. Of course you can also create a new [ feature issue] ( https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md )
367- if you're just wishing a feature ;)
36875
36976### Known issues
37077| Error | Solution |
37178| ------------------------------------------------------------------------- | ---------------------------------------------------------- |
37279| Kerberos error: No credentials cache file found (try running kinit) (...) | Uncomment "DISABLE_AUTHENTICATOR" inside and use the ` legacy-imap ` protocol ` config/imap.php ` |
37380
81+
82+ ## Support
83+ If you encounter any problems or if you find a bug, please don't hesitate to create a new
84+ [ issue] ( https://github.com/Webklex/laravel-imap/issues ) .
85+ However please be aware that it might take some time to get an answer.
86+
87+ Off topic, rude or abusive issues will be deleted without any notice.
88+
89+ If you need
** immediate
** or
** commercial
** support, feel free to send me a mail at
[email protected] .
90+
91+ +
92+ ##### A little notice
93+ If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read
94+ and people are more likely to comment and help :)
95+
96+ ` ;` ;` ; php
97+
98+ echo 'your php code...';
99+
100+ ` ;` ;` ;
101+
102+ will turn into:
103+ ``` php
104+ echo 'your php code...';
105+ ```
106+
107+ ### Features & pull requests
108+ Everyone can contribute to this project. Every pull request will be considered but it can also happen to be declined.
109+ To prevent unnecessary work, please consider to create a [ feature issue] ( https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md )
110+ first, if you're planning to do bigger changes. Of course you can also create a new [ feature issue] ( https://github.com/Webklex/laravel-imap/issues/new?template=feature_request.md )
111+ if you're just wishing a feature ;)
112+
113+
374114## Change log
375115Please see [ CHANGELOG] [ link-changelog ] for more information what has changed recently.
376116
0 commit comments