Skip to content

Commit 0a371db

Browse files
committed
doc: README
1 parent ce4f41f commit 0a371db

File tree

3 files changed

+65
-64
lines changed

3 files changed

+65
-64
lines changed

README.md

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,113 +20,114 @@
2020
</a>
2121
</p>
2222

23-
# Mail logger and viewer for Laravel
23+
# Laravel Mail Logger & Viewer
2424

25-
### Easily log, view and search in browser all outgoing emails.
25+
Easily log, view, and search outgoing emails directly in your browser.
2626

27-
![preview](https://github.com/MasterRO94/packages/blob/master/mail-viewer/Mail%20Viewer%20V2.png "Preview")
27+
![Preview Dark](./art/v3-dark.png "Preview Dark")
28+
![Preview Light](./art/v3-light.png "Preview Light")
2829

29-
This package gives an ability to log all outgoing emails to a database and view them all from a browser like they will
30-
be shown in a modern mail clients (gmail, etc.).
30+
This package logs all outgoing emails to a database and provides a web interface to view them, formatted as they appear in modern email clients like Gmail.
3131

32-
## Version Compatibility
32+
---
3333

34-
| Laravel | Mail Viewer |
35-
|:------------|:------------|
36-
| 5.5.x - 8.* | 1.3.x |
37-
| 9.x - 12.x | 2.x.x |
38-
| 12.x | 3.x.x |
39-
40-
## Upgrade from v1 to v2
41-
42-
Version 2 has been almost totally rewritten and brings totally new fresh UI build with Vue.js 3 and TailwindCss 3.
43-
It works **only with Laravel 9+** as of Symfony Mailer replacement for previously used Swift Mailer.
34+
## Installation
4435

45-
### Upgrade Steps
36+
### Step 1: Install via Composer
4637

47-
#### Composer Dependencies
38+
Run the following command in your terminal:
4839

49-
You should update the dependency in your application's composer.json file:
40+
```sh
41+
composer require masterro/laravel-mail-viewer
42+
```
5043

51-
`masterro/laravel-mail-viewer` to ^2.0
44+
### Step 2: Publish Assets & Configurations
5245

53-
#### Database migrations
46+
```sh
47+
php artisan mail-viewer:publish
48+
```
5449

55-
Run package migrations (requires `doctrine/dbal` to be installed):
50+
### Step 3: Run Migrations
5651

57-
```shell
52+
```sh
5853
php artisan migrate
5954
```
6055

61-
#### Publish assets
56+
### Step 4: View Emails
6257

63-
Run publish command:
58+
Visit `/_mail-viewer` in your browser to access the email viewer.
6459

65-
```shell
66-
php artisan mail-viewer:publish --views
67-
```
60+
> **Note:** The route can be customized in the configuration file.
6861
69-
#### Update configs
62+
---
7063

71-
V2 uses separate date format for date and time, update these in your `config/mail-viewer.php` file
64+
## Configuration
7265

73-
```php
74-
'date_format' => 'd.m.Y',
75-
'time_format' => 'H:i:s',
76-
```
66+
You can adjust default settings in the `config/mail-viewer.php` file.
7767

78-
#### Data pruning
68+
### Data Pruning
7969

80-
V2 allows prune old records easily using `mail-viewer:prune` command. You can add it to your Scheduler.
70+
The package supports Laravel's [Model Pruning](https://laravel.com/docs/eloquent#pruning-models). Define how many days emails should be retained in the configuration:
8171

8272
```php
83-
// Console/Kernel.php
84-
$schedule->command('mail-viewer:prune')->daily();
73+
'prune_older_than_days' => 365,
8574
```
8675

87-
You can specify how many days data will be stored before pruning using config. Default value is 31 days.
76+
---
8877

89-
```php
90-
'prune_older_than_days' => 31,
91-
```
78+
## Production Usage
9279

93-
## Installation
80+
By default, the email viewer is publicly accessible.
81+
In a production environment, it's highly recommended to restrict access
82+
using middleware or something like [Access Screen](https://github.com/MasterRO94/laravel-access-screen) package.
9483

95-
### Step 1: Composer
84+
### Restrict Access with Middleware
9685

97-
From the command line, run:
86+
Modify your `routes/web.php` to apply authentication:
9887

99-
```
100-
composer require masterro/laravel-mail-viewer
88+
```php
89+
'middleware' => ['web', 'can:viewMailLogs'],
10190
```
10291

103-
### Step 2: Publish assets and configs
92+
You can also limit access by IP address in `App\Http\Middleware\RestrictMailViewerAccess.php`:
10493

105-
```
106-
php artisan mail-viewer:publish
94+
```php
95+
namespace App\Http\Middleware;
96+
97+
use Closure;
98+
use Illuminate\Http\Request;
99+
100+
class RestrictMailViewerAccess
101+
{
102+
public function handle(Request $request, Closure $next)
103+
{
104+
if (!in_array($request->ip(), ['127.0.0.1', '::1', 'YOUR_ALLOWED_IP'])) {
105+
abort(403);
106+
}
107+
108+
return $next($request);
109+
}
110+
}
107111
```
108112

109-
You have to publish _**assets,**_ and _**views,**_ _configs_ are optional.
113+
Apply it in config:
110114

111-
### Step 3: Run migrations
115+
```php
112116

113-
```
114-
php artisan migrate
117+
'middleware' => ['web', RestrictMailViewerAccess::class],
115118
```
116119

117-
### Step 4: View emails
120+
Now, only authorized users or allowed IPs can access the mail viewer.
118121

119-
All ongoing emails you can find on `/_mail-viewer` page.
122+
---
120123

121-
## Configuration
124+
## License
122125

123-
You can review and change all the default configuration values in published `config/mail-viewer.php` file.
126+
This package is open-source software licensed under the [MIT license](LICENSE).
124127

125-
#### Data pruning (v2+)
128+
---
126129

127-
The package allows you to prune old records easily using `mail-viewer:prune` command. You can add it to your Scheduler.
130+
## Credits
131+
132+
Developed by [MasterRO](https://github.com/MasterRO94).
128133

129-
```php
130-
// Console/Kernel.php
131-
$schedule->command('mail-viewer:prune')->daily();
132-
```

art/v3-dark.png

299 KB
Loading

art/v3-light.png

258 KB
Loading

0 commit comments

Comments
 (0)