Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m7s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m52s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m31s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 53s
- Formular-Plugin: Baukasten mit 13 Feldtypen, Bedingungen, Vorbelegung aus dem Profil, Datei-Uploads (geschützt), anonyme Formulare, „nur einmal“, Einsendeschluss, Sichtbarkeit, Löschfrist; Einsendungen im Backend und per Mail (optional ohne Angaben, Kopie an die Person); Rechte je Formular und Rolle für Ansehen/Export und Löschen; CSV für Excel; Pagebuilder-Block - WordPress-Import (Plugin): WXR-Datei einlesen, Kategorien/Personen zuordnen, Beiträge mit Status, Datum, Beitragsbild und Bildern im Text übernehmen, optional Seiten mit Hierarchie; in Portionen, wiederholbar ohne Doppelungen - E-Mail-Versand im Admin (SMTP, verschlüsseltes Passwort, Test-Mail) - Speichertest unabhängig vom Verbrauch der Test-Suite Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
109 lines
4.4 KiB
PHP
109 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Support\Audit;
|
|
use App\Support\MailSettings;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Throwable;
|
|
use UnitEnum;
|
|
|
|
/**
|
|
* SMTP-Zugang für Benachrichtigungen, Formulare und „Passwort vergessen“.
|
|
*/
|
|
class MailSettingsPage extends Page
|
|
{
|
|
protected string $view = 'filament.pages.settings-form';
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedEnvelope;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'System';
|
|
|
|
protected static ?int $navigationSort = 5;
|
|
|
|
protected static ?string $navigationLabel = 'E-Mail-Versand';
|
|
|
|
protected static ?string $title = 'E-Mail-Versand';
|
|
|
|
protected static ?string $slug = 'e-mail';
|
|
|
|
/** @var array<string, mixed>|null */
|
|
public ?array $data = [];
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
return auth()->user()?->can('mail.manage') ?? false;
|
|
}
|
|
|
|
public function mount(MailSettings $mail): void
|
|
{
|
|
$this->form->fill([...$mail->values(), 'password' => null]);
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
$smtp = fn (Get $get) => $get('mailer') === 'smtp';
|
|
|
|
return $schema
|
|
->components([
|
|
Section::make('Versand')
|
|
->description('Die Zugangsdaten erhalten Sie von Ihrem Hoster oder Ihrer IT (z. B. Microsoft 365: smtp.office365.com, Port 587, TLS).')
|
|
->columns(2)
|
|
->schema([
|
|
Select::make('mailer')->label('Versandart')->options(MailSettings::MAILERS)->required()->live()->native(false)->columnSpanFull(),
|
|
TextInput::make('host')->label('SMTP-Server')->required($smtp)->visible($smtp)->maxLength(255),
|
|
TextInput::make('port')->label('Port')->numeric()->required($smtp)->visible($smtp)->minValue(1)->maxValue(65535),
|
|
Select::make('encryption')->label('Verschlüsselung')->visible($smtp)->native(false)
|
|
->options(['tls' => 'STARTTLS (meist Port 587)', 'ssl' => 'SSL/TLS (meist Port 465)', 'none' => 'Keine']),
|
|
TextInput::make('username')->label('Benutzername')->visible($smtp)->maxLength(255)->autocomplete('off'),
|
|
TextInput::make('password')->label('Passwort')->password()->revealable()->visible($smtp)->maxLength(255)
|
|
->helperText('Leer lassen, um das gespeicherte Passwort zu behalten.')->autocomplete('new-password'),
|
|
]),
|
|
Section::make('Absender')
|
|
->columns(2)
|
|
->schema([
|
|
TextInput::make('from_address')->label('Absenderadresse')->email()->required()->maxLength(255)->placeholder('intranet@firma.de'),
|
|
TextInput::make('from_name')->label('Absendername')->maxLength(100)->placeholder('Name des Portals'),
|
|
]),
|
|
])
|
|
->statePath('data');
|
|
}
|
|
|
|
public function save(MailSettings $mail): void
|
|
{
|
|
$mail->save($this->form->getState());
|
|
Audit::log('mail.settings_updated');
|
|
|
|
Notification::make()->success()->title('E-Mail-Versand gespeichert')->send();
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('test')
|
|
->label('Test-Mail senden')
|
|
->icon(Heroicon::OutlinedPaperAirplane)
|
|
->color('gray')
|
|
->action(function () {
|
|
$to = auth()->user()->email;
|
|
|
|
try {
|
|
Mail::raw('Diese Test-Mail bestätigt, dass der E-Mail-Versand des Portals funktioniert.', fn ($m) => $m->to($to)->subject('Test-Mail aus dem Portal'));
|
|
Notification::make()->success()->title('Test-Mail an '.$to.' gesendet')->send();
|
|
} catch (Throwable $e) {
|
|
Notification::make()->danger()->title('Versand fehlgeschlagen')->body($e->getMessage())->persistent()->send();
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
}
|