|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(); } }), ]; } }