diff --git a/.env b/.env index aa08cd38..35f7980f 100644 --- a/.env +++ b/.env @@ -48,14 +48,14 @@ REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379 -MAIL_MAILER=log -MAIL_HOST=127.0.0.1 -MAIL_PORT=2525 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS="hello@example.com" -MAIL_FROM_NAME="${APP_NAME}" +MAIL_MAILER=smtp +MAIL_HOST=smtp.gmail.com +MAIL_PORT=587 +MAIL_USERNAME=system@deafgain.org +MAIL_PASSWORD=ojvlysraxwjriwzy +MAIL_ENCRYPTION=tls +MAIL_FROM_ADDRESS="system@deafgain.org" +MAIL_FROM_NAME="MAD Lawsuit Court Docket" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= diff --git a/app/Http/Controllers/Admin/DocketEntryController.php b/app/Http/Controllers/Admin/DocketEntryController.php index aced955a..daca9b4a 100644 --- a/app/Http/Controllers/Admin/DocketEntryController.php +++ b/app/Http/Controllers/Admin/DocketEntryController.php @@ -4,7 +4,11 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\DocketEntry; +use App\Models\Subscription; +use App\Mail\NewDocketEntryNotification; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Log; use Inertia\Inertia; use Inertia\Response; use Illuminate\Http\RedirectResponse; @@ -59,8 +63,12 @@ class DocketEntryController extends Controller $entry = DocketEntry::create($validated); + // Send email notifications to active subscribers + // TESTING MODE: Only send to chris@deafgain.org + $this->sendEmailNotifications($entry); + return redirect()->route('admin.docket-entries.show', $entry->id) - ->with('success', 'Docket entry created successfully.'); + ->with('success', 'Docket entry created successfully. Email notifications sent.'); } /** @@ -133,4 +141,45 @@ class DocketEntryController extends Controller return redirect()->route('admin.docket-entries.index') ->with('success', 'Docket entry deleted successfully.'); } + + /** + * Send email notifications to subscribers. + * TESTING MODE: Only sends to chris@deafgain.org + */ + private function sendEmailNotifications(DocketEntry $entry): void + { + try { + // TESTING MODE: Only send to chris@deafgain.org + // In production, this would query all active subscribers + $testEmail = 'chris@deafgain.org'; + $testToken = 'test-unsubscribe-token'; // Placeholder for testing + + Log::info('Sending email notification for new docket entry', [ + 'entry_id' => $entry->id, + 'entry_title' => $entry->title, + 'recipient' => $testEmail, + ]); + + Mail::to($testEmail)->send(new NewDocketEntryNotification($entry, $testToken)); + + Log::info('Email notification sent successfully', [ + 'entry_id' => $entry->id, + 'recipient' => $testEmail, + ]); + + // Production code (commented out for testing): + // $subscribers = Subscription::where('is_active', true)->get(); + // foreach ($subscribers as $subscriber) { + // Mail::to($subscriber->email)->send( + // new NewDocketEntryNotification($entry, $subscriber->unsubscribe_token) + // ); + // } + } catch (\Exception $e) { + Log::error('Failed to send email notification', [ + 'entry_id' => $entry->id, + 'error' => $e->getMessage(), + ]); + // Don't throw exception - we don't want email failures to break the entry creation + } + } } diff --git a/app/Mail/NewDocketEntryNotification.php b/app/Mail/NewDocketEntryNotification.php new file mode 100644 index 00000000..44d77583 --- /dev/null +++ b/app/Mail/NewDocketEntryNotification.php @@ -0,0 +1,56 @@ +entry->title, + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: 'emails.new-docket-entry', + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/emails/new-docket-entry.blade.php b/resources/views/emails/new-docket-entry.blade.php new file mode 100644 index 00000000..3d844971 --- /dev/null +++ b/resources/views/emails/new-docket-entry.blade.php @@ -0,0 +1,153 @@ + + + + + + New Court Filing Notification + + + +
+
+

New Court Filing

+

Eliza Kragh v. Montana Association of the Deaf

+
+ +
+

A new document has been filed in the case:

+ +
+
Filing Date
+
{{ $entry->date->format('F j, Y') }}
+ +
Title
+
{{ $entry->title }}
+ +
Summary
+
{{ $entry->summary }}
+
+ +
+ View Full Docket +
+ +
+ +

+ You are receiving this email because you subscribed to notifications for new court filings in this case. +

+
+ + +
+ +