Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d9074e8

Browse files
authoredDec 31, 2024··
feat: [LAR-164] add filament mails logger (#288)
1 parent aa3ab10 commit d9074e8

9 files changed

+681
-1
lines changed
 

‎app/Providers/Filament/AdminPanelProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Illuminate\Session\Middleware\StartSession;
2222
use Illuminate\Support\Facades\Blade;
2323
use Illuminate\View\Middleware\ShareErrorsFromSession;
24+
use Vormkracht10\FilamentMails\FilamentMailsPlugin;
2425

2526
final class AdminPanelProvider extends PanelProvider
2627
{
@@ -51,6 +52,7 @@ public function panel(Panel $panel): Panel
5152
->plugins([
5253
SpatieLaravelTranslatablePlugin::make()
5354
->defaultLocales(['fr', 'en']),
55+
FilamentMailsPlugin::make(),
5456
])
5557
->renderHook(
5658
'body.start',

‎composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"symfony/http-client": "^7.1.8",
4747
"symfony/mailgun-mailer": "^7.1",
4848
"torchlight/torchlight-laravel": "^0.6",
49+
"vormkracht10/filament-mails": "^1.0",
4950
"wire-elements/modal": "^2.0",
5051
"wire-elements/spotlight": "^2.0",
5152
"yarri/link-finder": "^2.7.10",

‎composer.lock

Lines changed: 398 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/filament-mails.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Vormkracht10\FilamentMails\Resources\EventResource;
6+
use Vormkracht10\FilamentMails\Resources\MailResource;
7+
8+
return [
9+
'resources' => [
10+
'mail' => MailResource::class,
11+
'event' => EventResource::class,
12+
],
13+
];

‎config/mails.php

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Vormkracht10\Mails\Models\Mail;
6+
use Vormkracht10\Mails\Models\MailAttachment;
7+
use Vormkracht10\Mails\Models\MailEvent;
8+
9+
return [
10+
11+
// Eloquent model to use for sent emails
12+
13+
'models' => [
14+
'mail' => Mail::class,
15+
'event' => MailEvent::class,
16+
'attachment' => MailAttachment::class,
17+
],
18+
19+
// Table names for saving sent emails and polymorphic relations to database
20+
21+
'database' => [
22+
'tables' => [
23+
'mails' => 'mails',
24+
'attachments' => 'mail_attachments',
25+
'events' => 'mail_events',
26+
'polymorph' => 'mailables',
27+
],
28+
29+
'pruning' => [
30+
'enabled' => true,
31+
'after' => 30, // days
32+
],
33+
],
34+
35+
'headers' => [
36+
'uuid' => 'X-Mails-UUID',
37+
38+
'associate' => 'X-Mails-Associated-Models',
39+
],
40+
41+
'webhooks' => [
42+
'routes' => [
43+
'prefix' => 'webhooks/mails',
44+
],
45+
46+
'queue' => env('MAILS_QUEUE_WEBHOOKS', false),
47+
],
48+
49+
// Logging mails
50+
'logging' => [
51+
52+
// Enable logging of all sent mails to database
53+
54+
'enabled' => env('MAILS_LOGGING_ENABLED', true),
55+
56+
// Specify attributes to log in database
57+
58+
'attributes' => [
59+
'subject',
60+
'from',
61+
'to',
62+
'reply_to',
63+
'cc',
64+
'bcc',
65+
'html',
66+
'text',
67+
],
68+
69+
// Encrypt all attributes saved to database
70+
71+
'encrypted' => env('MAILS_ENCRYPTED', true),
72+
73+
// Track following events using webhooks from email provider
74+
75+
'tracking' => [
76+
'bounces' => true,
77+
'clicks' => true,
78+
'complaints' => true,
79+
'deliveries' => true,
80+
'opens' => true,
81+
'unsubscribes' => true,
82+
],
83+
84+
// Enable saving mail attachments to disk
85+
86+
'attachments' => [
87+
'enabled' => env('MAILS_LOGGING_ATTACHMENTS_ENABLED', true),
88+
'disk' => env('FILESYSTEM_DISK', 'local'),
89+
'root' => 'mails/attachments',
90+
],
91+
],
92+
93+
// Notifications for important mail events
94+
95+
'notifications' => [
96+
'mail' => [
97+
'to' => [
98+
env('MAIL_SUPPORT'),
99+
],
100+
],
101+
102+
'discord' => [
103+
// 'to' => ['1234567890'],
104+
],
105+
106+
'slack' => [
107+
// 'to' => ['https://hooks.slack.com/services/...'],
108+
],
109+
110+
'telegram' => [
111+
// 'to' => ['1234567890'],
112+
],
113+
],
114+
115+
'events' => [
116+
'soft_bounced' => [
117+
'notify' => ['mail'],
118+
],
119+
120+
'hard_bounced' => [
121+
'notify' => ['mail'],
122+
],
123+
124+
'bouncerate' => [
125+
'notify' => [],
126+
127+
'retain' => 30, // days
128+
129+
'treshold' => 1, // %
130+
],
131+
132+
'deliveryrate' => [
133+
'treshold' => 99,
134+
],
135+
136+
'complained' => [
137+
//
138+
],
139+
140+
'unsent' => [
141+
//
142+
],
143+
],
144+
145+
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create(config('mails.database.tables.mails'), function (Blueprint $table): void {
14+
$table->id();
15+
$table->string('uuid')->nullable()->index();
16+
$table->string('mail_class')->nullable()->index();
17+
$table->string('subject')->nullable();
18+
$table->json('from')->nullable();
19+
$table->json('reply_to')->nullable();
20+
$table->json('to')->nullable();
21+
$table->json('cc')->nullable();
22+
$table->json('bcc')->nullable();
23+
$table->text('html')->nullable();
24+
$table->text('text')->nullable();
25+
$table->unsignedBigInteger('opens')->default(0);
26+
$table->unsignedBigInteger('clicks')->default(0);
27+
$table->timestamp('sent_at')->nullable();
28+
$table->timestamp('resent_at')->nullable();
29+
$table->timestamp('accepted_at')->nullable();
30+
$table->timestamp('delivered_at')->nullable();
31+
$table->timestamp('last_opened_at')->nullable();
32+
$table->timestamp('last_clicked_at')->nullable();
33+
$table->timestamp('complained_at')->nullable();
34+
$table->timestamp('soft_bounced_at')->nullable();
35+
$table->timestamp('hard_bounced_at')->nullable();
36+
$table->timestamp('unsubscribed_at')->nullable();
37+
$table->timestamps();
38+
});
39+
}
40+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create(config('mails.database.tables.attachments', 'mail_attachments'), function (Blueprint $table): void {
14+
$table->id();
15+
$table->foreignIdFor(config('mails.models.mail'))
16+
->constrained()
17+
->cascadeOnDelete();
18+
$table->string('disk');
19+
$table->string('uuid');
20+
$table->string('filename');
21+
$table->string('mime');
22+
$table->boolean('inline', false);
23+
$table->bigInteger('size');
24+
$table->timestamps();
25+
});
26+
}
27+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create(config('mails.database.tables.events', 'mail_events'), function (Blueprint $table): void {
14+
$table->id();
15+
$table->foreignIdFor(config('mails.models.mail'))
16+
->constrained()
17+
->cascadeOnDelete();
18+
$table->string('type');
19+
$table->string('ip_address')->nullable();
20+
$table->string('hostname')->nullable();
21+
$table->string('platform')->nullable();
22+
$table->string('os')->nullable();
23+
$table->string('browser')->nullable();
24+
$table->string('user_agent')->nullable();
25+
$table->string('city')->nullable();
26+
$table->char('country_code', 2)->nullable();
27+
$table->string('link')->nullable();
28+
$table->string('tag')->nullable();
29+
$table->json('payload')->nullable();
30+
$table->timestamps();
31+
$table->timestamp('occurred_at')->nullable();
32+
});
33+
}
34+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
9+
return new class extends Migration
10+
{
11+
public function up(): void
12+
{
13+
Schema::create(config('mails.database.tables.polymorph'), function (Blueprint $table): void {
14+
$table->id();
15+
$table->foreignIdFor(config('mails.models.mail'))
16+
->constrained()
17+
->cascadeOnDelete();
18+
$table->morphs('mailable');
19+
});
20+
}
21+
};

0 commit comments

Comments
 (0)
Please sign in to comment.