Skip to content

Commit d605fb2

Browse files
authored
V3 Release
V3 Release
2 parents 723030c + 058f149 commit d605fb2

File tree

117 files changed

+10937
-19104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+10937
-19104
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [8.1, 8.2, 8.3, 8.4]
16+
php: [8.2, 8.3, 8.4, 8.5]
1717
stability: [prefer-lowest, prefer-stable]
18-
exclude:
19-
- php: 8.2
20-
stability: prefer-lowest
21-
22-
- php: 8.3
23-
stability: prefer-lowest
2418

2519
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
2620

@@ -39,4 +33,4 @@ jobs:
3933
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
4034

4135
- name: Execute tests
42-
run: vendor/bin/phpunit
36+
run: vendor/bin/pest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ composer.lock
55
.idea
66
.phpunit.result.cache
77
.phpunit.cache
8+
.eslintcache

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resources/old-assets/*

.prettierrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"singleAttributePerLine": true,
5+
"htmlWhitespaceSensitivity": "css",
6+
"printWidth": 150,
7+
"plugins": [
8+
"prettier-plugin-organize-imports",
9+
"prettier-plugin-tailwindcss"
10+
],
11+
"tailwindFunctions": [
12+
"clsx",
13+
"cn"
14+
],
15+
"tabWidth": 2
16+
}

README.md

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

23-
# Mail logger and viewer for Laravel
23+
# Laravel Mail Viewer
24+
25+
Easily log, view, and search outgoing emails directly in your browser.
26+
27+
![Screenshot of Laravel Mail Viewer - Light Mode](./art/v3-light.png "Preview Light")
28+
![Screenshot of Laravel Mail Viewer - Dark Mode](./art/v3-dark.png "Preview Dark")
29+
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.
31+
32+
---
33+
34+
<!-- TOC -->
35+
* [Laravel Mail Viewer](#laravel-mail-viewer)
36+
* [Features](#features)
37+
* [Installation](#installation)
38+
* [Step 1: Install via Composer](#step-1-install-via-composer)
39+
* [Step 2: Publish Assets & Configurations](#step-2-publish-assets--configurations)
40+
* [Step 3: Run Migrations](#step-3-run-migrations)
41+
* [Step 4: View Emails](#step-4-view-emails)
42+
* [Configuration](#configuration)
43+
* [Data Pruning](#data-pruning)
44+
* [Production Usage](#production-usage)
45+
* [Restrict Access with Middleware](#restrict-access-with-middleware)
46+
* [Disable package in production mode](#disable-package-in-production-mode)
47+
* [Disable auto-discovery:](#disable-auto-discovery)
48+
* [Register package for non-production environments](#register-package-for-non-production-environments)
49+
* [License](#license)
50+
* [Credits](#credits)
51+
<!-- TOC -->
52+
53+
## Features
54+
- Logs all outgoing emails to the database
55+
- Modern in-browser email viewer
56+
- Searchable UI with auto-refreshing entries
57+
- Configurable route and access protection
58+
- Optional email pruning
2459

25-
### Easily log, view and search in browser all outgoing emails.
60+
## Installation
61+
### Step 1: Install via Composer
62+
63+
Run the following command in your terminal:
64+
65+
```sh
66+
composer require masterro/laravel-mail-viewer
67+
```
2668

27-
![preview](https://github.com/MasterRO94/packages/blob/master/mail-viewer/Mail%20Viewer%20V2.png "Preview")
69+
### Step 2: Publish Assets & Configurations
2870

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.).
71+
```sh
72+
php artisan mail-viewer:publish
73+
```
3174

32-
## Version Compatibility
75+
### Step 3: Run Migrations
3376

34-
| Laravel | Mail Viewer |
35-
|:------------|:------------|
36-
| 5.5.x - 8.* | 1.3.x |
37-
| 9.x - 10.x | 2.x.x |
77+
```sh
78+
php artisan migrate
79+
```
3880

39-
## Upgrade from v1 to v2
81+
### Step 4: View Emails
4082

41-
Version 2 has been almost totally rewritten and brings totally new fresh UI build with Vue.js 3 and TailwindCss 3.
42-
It works **only with Laravel 9+** as of Symfony Mailer replacement for previously used Swift Mailer.
83+
Visit `/_mail-viewer` in your browser to access the email viewer.
4384

44-
### Upgrade Steps
85+
> **Note:** The route can be customized in the configuration file.
4586
46-
#### Composer Dependencies
87+
---
4788

48-
You should update the dependency in your application's composer.json file:
89+
## Configuration
4990

50-
`masterro/laravel-mail-viewer` to ^2.0
91+
You can adjust default settings in the `config/mail-viewer.php` file.
5192

52-
#### Database migrations
93+
### Data Pruning
5394

54-
Run package migrations (requires `doctrine/dbal` to be installed):
95+
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:
5596

56-
```shell
57-
php artisan migrate
97+
```php
98+
'prune_older_than_days' => 365,
5899
```
59100

60-
#### Publish assets
101+
---
61102

62-
Run publish command:
103+
## Production Usage
63104

64-
```shell
65-
php artisan mail-viewer:publish --views
66-
```
105+
By default, the email viewer is publicly accessible.
106+
In a production environment, it's highly recommended to restrict access
107+
using middleware or something like [Access Screen](https://github.com/MasterRO94/laravel-access-screen) package.
108+
Alternatively, you can disable the package in production environments.
67109

68-
#### Update configs
110+
### Restrict Access with Middleware
69111

70-
V2 uses separate date format for date and time, update these in your `config/mail-viewer.php` file
112+
Modify your `config/mail-viewer.php` to apply authorization:
71113

72114
```php
73-
'date_format' => 'd.m.Y',
74-
'time_format' => 'H:i:s',
115+
'middleware' => ['web', 'can:viewMailLogs'],
75116
```
76117

77-
#### Data pruning
118+
> **Note:** `viewMailLogs` is just an example ability you can register via Laravel’s [Authorization Gate](https://laravel.com/docs/authorization#writing-gates).
119+
> This ability is not included in the package.
78120
79-
V2 allows prune old records easily using `mail-viewer:prune` command. You can add it to your Scheduler.
121+
You can also limit access by IP address in `App\Http\Middleware\RestrictMailViewerAccess.php`:
80122

81123
```php
82-
// Console/Kernel.php
83-
$schedule->command('mail-viewer:prune')->daily();
124+
namespace App\Http\Middleware;
125+
126+
use Closure;
127+
use Illuminate\Http\Request;
128+
129+
class RestrictMailViewerAccess
130+
{
131+
public function handle(Request $request, Closure $next)
132+
{
133+
if (!in_array($request->ip(), ['127.0.0.1', '::1', 'YOUR_ALLOWED_IP'])) {
134+
abort(403);
135+
}
136+
137+
return $next($request);
138+
}
139+
}
84140
```
85141

86-
You can specify how many days data will be stored before pruning using config. Default value is 31 days.
142+
Apply it in config:
87143

88144
```php
89-
'prune_older_than_days' => 31,
145+
'middleware' => ['web', RestrictMailViewerAccess::class],
90146
```
91147

92-
## Installation
93-
94-
### Step 1: Composer
148+
Now, only authorized users or allowed IPs can access the mail viewer.
95149

96-
From the command line, run:
150+
---
97151

152+
### Disable package in production mode
153+
#### Disable auto-discovery:
154+
```json
155+
"extra": {
156+
"laravel": {
157+
"dont-discover": [
158+
"masterro/laravel-mail-viewer"
159+
]
160+
}
161+
},
98162
```
99-
composer require masterro/laravel-mail-viewer
100-
```
101-
102-
### Step 2: Publish assets and configs
103-
104-
```
105-
php artisan mail-viewer:publish
106-
```
107-
108-
You have to publish _**assets,**_ and _**views,**_ _configs_ are optional.
109-
110-
### Step 3: Run migrations
111163

112-
```
113-
php artisan migrate
164+
#### Register package for non-production environments
165+
In your application's `ServiceProvider`
166+
```php
167+
use MasterRO\MailViewer\Providers\MailViewerServiceProvider;
168+
169+
public function register(): void
170+
{
171+
if (!$this->app->environment('production')) {
172+
$this->app->register(MailViewerServiceProvider::class);
173+
}
174+
}
114175
```
115176

116-
### Step 4: View emails
177+
## License
117178

118-
All ongoing emails you can find on `/_mail-viewer` page.
179+
This package is open-source software licensed under the [MIT license](LICENSE).
119180

120-
## Configuration
181+
---
121182

122-
You can review and change all the default configuration values in published `config/mail-viewer.php` file.
183+
## Credits
123184

124-
#### Data pruning (v2+)
185+
Developed by [MasterRO](https://github.com/MasterRO94).
125186

126-
The package allows you to prune old records easily using `mail-viewer:prune` command. You can add it to your Scheduler.
127-
128-
```php
129-
// Console/Kernel.php
130-
$schedule->command('mail-viewer:prune')->daily();
131-
```

art/v3-dark.png

297 KB
Loading

art/v3-light.png

268 KB
Loading

composer.json

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@
1515
"log"
1616
],
1717
"require": {
18-
"illuminate/support": "^9.0|^10.0|^11.0|^12.0",
19-
"illuminate/events": "^9.0|^10.0|^11.0|^12.0",
20-
"illuminate/database": "^9.0|^10.0|^11.0|^12.0",
21-
"illuminate/routing": "^9.0|^10.0|^11.0|^12.0",
22-
"illuminate/view": "^9.0|^10.0|^11.0|^12.0",
23-
"illuminate/mail": "^9.0|^10.0|^11.0|^12.0",
2418
"doctrine/dbal": "^3.5 | ^4.0 | ^5.0",
25-
"nesbot/carbon": ">=2.62.1"
19+
"illuminate/database": "^10.0|^11.0|^12.0",
20+
"illuminate/events": "^10.0|^11.0|^12.0",
21+
"illuminate/mail": "^10.0|^11.0|^12.0",
22+
"illuminate/routing": "^10.0|^11.0|^12.0",
23+
"illuminate/support": "^10.0|^11.0|^12.0",
24+
"illuminate/view": "^10.0|^11.0|^12.0",
25+
"nesbot/carbon": ">=2.62.1",
26+
"opcodesio/mail-parser": "^0.2.1"
2627
},
2728
"require-dev": {
28-
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0"
29+
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
30+
"pestphp/pest": "^3.8"
2931
},
3032
"autoload": {
3133
"psr-4": {
32-
"MasterRO\\MailViewer\\": "src/app",
34+
"MasterRO\\MailViewer\\": "src/",
3335
"MasterRO\\MailViewer\\Tests\\": "tests/"
3436
}
3537
},
3638
"minimum-stability": "dev",
3739
"prefer-stable": true,
3840
"config": {
3941
"sort-packages": true,
40-
"optimize-autoloader": true
42+
"optimize-autoloader": true,
43+
"allow-plugins": {
44+
"pestphp/pest-plugin": true
45+
}
46+
},
47+
"scripts": {
48+
"test": "./vendor/bin/pest"
4149
},
4250
"extra": {
4351
"laravel": {

config/mail-viewer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'table' => 'mail_logs',
7+
'middleware' => ['web'],
8+
'uri_prefix' => env('MAIL_VIEWER_URI_PREFIX', '_mail-viewer'),
9+
'date_format' => env('MAIL_VIEWER_DATE_FORMAT', 'd.m.Y'),
10+
'time_format' => env('MAIL_VIEWER_DATE_FORMAT', 'H:i:s'),
11+
'timezone' => env('MAIL_VIEWER_TIMEZONE', env('APP_TIMEZONE', 'UTC')),
12+
'emails_per_page' => env('MAIL_VIEWER_EMAILS_PER_PAGE', 20),
13+
'prune_older_than_days' => env('MAIL_VIEWER_PRUNE_OLDER_THAN_DAYS', 0),
14+
'site_url' => env('MAIL_VIEWER_SITE_URL'),
15+
];

src/database/migrations/2018_01_12_161325_create_mail_logs_table.php.php renamed to database/migrations/2018_01_12_161325_create_mail_logs_table.php.php

File renamed without changes.

0 commit comments

Comments
 (0)