diff --git a/app/Http/Controllers/Admin/MailProfileController.php b/app/Http/Controllers/Admin/MailProfileController.php index a4dfeb9..0ef84ce 100644 --- a/app/Http/Controllers/Admin/MailProfileController.php +++ b/app/Http/Controllers/Admin/MailProfileController.php @@ -26,7 +26,7 @@ public function index(): Response ->orderBy('priority') ->orderBy('id') ->get([ - 'id', 'name', 'active', 'host', 'port', 'username', 'from_name', 'encryption', 'from_address', 'priority', 'signature', 'last_success_at', 'last_error_at', 'last_error_message', 'test_status', 'test_checked_at', + 'id', 'name', 'active', 'auto_mailer', 'host', 'port', 'username', 'from_name', 'encryption', 'from_address', 'priority', 'signature', 'last_success_at', 'last_error_at', 'last_error_message', 'test_status', 'test_checked_at', ]); return Inertia::render('Admin/MailProfiles/Index', [ @@ -76,6 +76,15 @@ public function toggle(Request $request, MailProfile $mailProfile) return back()->with('success', 'Status updated'); } + public function toggleAutoMailer(Request $request, MailProfile $mailProfile) + { + $this->authorize('update', $mailProfile); + $mailProfile->auto_mailer = ! $mailProfile->auto_mailer; + $mailProfile->save(); + + return back()->with('success', 'Auto-mailer updated'); + } + public function test(Request $request, MailProfile $mailProfile) { $this->authorize('test', $mailProfile); diff --git a/app/Http/Requests/StoreMailProfileRequest.php b/app/Http/Requests/StoreMailProfileRequest.php index 1f008c0..48783c2 100644 --- a/app/Http/Requests/StoreMailProfileRequest.php +++ b/app/Http/Requests/StoreMailProfileRequest.php @@ -28,6 +28,7 @@ public function rules(): array 'max_daily_quota' => ['nullable', 'integer', 'min:0'], 'signature' => ['nullable', 'array'], 'signature.*' => ['nullable', 'string', 'max:1000'], + 'auto_mailer' => ['nullable', 'boolean'], ]; } } diff --git a/app/Http/Requests/UpdateMailProfileRequest.php b/app/Http/Requests/UpdateMailProfileRequest.php index 1da0b01..f16e437 100644 --- a/app/Http/Requests/UpdateMailProfileRequest.php +++ b/app/Http/Requests/UpdateMailProfileRequest.php @@ -29,6 +29,7 @@ public function rules(): array 'active' => ['nullable', 'boolean'], 'signature' => ['nullable', 'array'], 'signature.*' => ['nullable', 'string', 'max:1000'], + 'auto_mailer' => ['nullable', 'boolean'], ]; } } diff --git a/app/Models/MailProfile.php b/app/Models/MailProfile.php index 8cd45f2..0bfed29 100644 --- a/app/Models/MailProfile.php +++ b/app/Models/MailProfile.php @@ -10,13 +10,14 @@ class MailProfile extends Model use HasFactory; protected $fillable = [ - 'name', 'active', 'host', 'port', 'encryption', 'username', 'from_address', 'from_name', + 'name', 'active', 'auto_mailer', 'host', 'port', 'encryption', 'username', 'from_address', 'from_name', 'reply_to_address', 'reply_to_name', 'priority', 'signature', 'max_daily_quota', 'emails_sent_today', 'last_success_at', 'last_error_at', 'last_error_message', 'failover_to_id', 'test_status', 'test_checked_at', ]; protected $casts = [ 'active' => 'boolean', + 'auto_mailer' => 'boolean', 'signature' => 'array', 'last_success_at' => 'datetime', 'last_error_at' => 'datetime', diff --git a/app/Services/AutoMailDispatcher.php b/app/Services/AutoMailDispatcher.php index fef6d9b..8748b76 100644 --- a/app/Services/AutoMailDispatcher.php +++ b/app/Services/AutoMailDispatcher.php @@ -100,6 +100,12 @@ public function maybeQueue(Activity $activity, bool $sendFlag = true, array $opt $mailProfile = isset($options['mail_profile_id']) ? MailProfile::query()->find($options['mail_profile_id']) : null; + $mailProfile ??= MailProfile::query() + ->where('active', true) + ->where('auto_mailer', true) + ->orderBy('priority') + ->orderBy('id') + ->first(); $mailProfile ??= MailProfile::query() ->where('active', true) ->orderBy('priority') diff --git a/database/migrations/2026_05_11_000001_add_auto_mailer_to_mail_profiles_table.php b/database/migrations/2026_05_11_000001_add_auto_mailer_to_mail_profiles_table.php new file mode 100644 index 0000000..fd08f9f --- /dev/null +++ b/database/migrations/2026_05_11_000001_add_auto_mailer_to_mail_profiles_table.php @@ -0,0 +1,22 @@ +boolean('auto_mailer')->default(false)->after('active'); + }); + } + + public function down(): void + { + Schema::table('mail_profiles', function (Blueprint $table): void { + $table->dropColumn('auto_mailer'); + }); + } +}; diff --git a/resources/js/Pages/Admin/MailProfiles/Index.vue b/resources/js/Pages/Admin/MailProfiles/Index.vue index 08e449d..f5133d5 100644 --- a/resources/js/Pages/Admin/MailProfiles/Index.vue +++ b/resources/js/Pages/Admin/MailProfiles/Index.vue @@ -99,6 +99,7 @@ const form = useForm({ from_address: "", from_name: "", priority: 10, + auto_mailer: false, }); function openCreate() { @@ -120,6 +121,7 @@ function openEdit(p) { form.from_address = p.from_address || ""; form.from_name = p.from_name || ""; form.priority = p.priority ?? 10; + form.auto_mailer = p.auto_mailer ?? false; editTarget.value = p; signatureItems.value = signatureFromObject(p.signature); editOpen.value = true; @@ -159,6 +161,7 @@ function submitEdit() { from_address: form.from_address, from_name: form.from_name || null, priority: form.priority, + auto_mailer: form.auto_mailer, signature: signatureToObject(), }; if (form.password && form.password.trim() !== "") { @@ -181,6 +184,12 @@ function toggleActive(p) { .then(() => window.location.reload()); } +function toggleAutoMailer(p) { + window.axios + .post(route("admin.mail-profiles.toggle-auto-mailer", p.id)) + .then(() => window.location.reload()); +} + function testConnection(p) { window.axios .post(route("admin.mail-profiles.test", p.id)) @@ -238,6 +247,7 @@ const statusClass = (p) => { Port Enc Aktivno + Auto-mailer Status Zadnji uspeh Napaka @@ -261,6 +271,12 @@ const statusClass = (p) => { @update:model-value="() => toggleActive(p)" /> + + + { +
+ + +
@@ -487,6 +511,14 @@ const statusClass = (p) => {
+
+ + +
diff --git a/routes/web.php b/routes/web.php index 162f5a8..f8ed55e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -114,6 +114,7 @@ Route::post('mail-profiles', [\App\Http\Controllers\Admin\MailProfileController::class, 'store'])->name('mail-profiles.store'); Route::put('mail-profiles/{mailProfile}', [\App\Http\Controllers\Admin\MailProfileController::class, 'update'])->name('mail-profiles.update'); Route::post('mail-profiles/{mailProfile}/toggle', [\App\Http\Controllers\Admin\MailProfileController::class, 'toggle'])->name('mail-profiles.toggle'); + Route::post('mail-profiles/{mailProfile}/toggle-auto-mailer', [\App\Http\Controllers\Admin\MailProfileController::class, 'toggleAutoMailer'])->name('mail-profiles.toggle-auto-mailer'); Route::post('mail-profiles/{mailProfile}/test', [\App\Http\Controllers\Admin\MailProfileController::class, 'test'])->name('mail-profiles.test'); Route::post('mail-profiles/{mailProfile}/send-test', [\App\Http\Controllers\Admin\MailProfileController::class, 'sendTest'])->name('mail-profiles.send-test'); Route::delete('mail-profiles/{mailProfile}', [\App\Http\Controllers\Admin\MailProfileController::class, 'destroy'])->name('mail-profiles.destroy');