authorize('mail.manage'); } /** * Send one to the signed-in operator. * * To themselves and nobody else — no address field. A preview that can be * addressed is a form for sending mail to strangers from inside the console, * which is not what this is for and not something to leave lying about. */ public function sendToMe(string $key): void { $this->authorize('mail.manage'); $operator = Auth::guard('operator')->user(); $mailable = app(MailPreviews::class)->make($key); if ($operator === null || $mailable === null) { return; } try { // sendNow(), not send(): every mailable here implements ShouldQueue, // and send() silently defers to queue() for those — which would put // a failure in a worker's log while the button reported success. The // person pressing it is waiting for the mail, so the send happens in // their request and its failure reaches them. Mail::to($operator->email)->sendNow($mailable); } catch (Throwable $e) { $this->dispatch('notify', message: __('mail_preview.failed', [ 'reason' => mb_substr($e->getMessage(), 0, 160), ])); return; } $this->dispatch('notify', message: __('mail_preview.sent', ['email' => $operator->email])); } public function render() { $this->authorize('mail.manage'); return view('livewire.admin.mail-preview', [ 'previews' => app(MailPreviews::class)->all(), 'me' => Auth::guard('operator')->user()?->email ?? '', // A preview that goes nowhere is worse than none: with a // non-delivering mailer the browser view still works and the send // silently writes to a file. 'delivers' => ! in_array(config('mail.default'), ['log', 'array', null], true), ]); } }