feat: complete email infrastructure with queue, templates, logging, and API
Adds the full transactional email system:
- Redis queue (QUEUE_CONNECTION=redis), SES config in .env.example
- 3 migrations: organisation_email_settings, organisation_email_templates, email_logs
- EmailTemplateType and EmailLogStatus enums with Dutch defaults
- EmailService as central entry point for all email sending
- SendTransactionalEmail queued job with retries and idempotency
- TransactionalMail mailable with responsive HTML + plain text templates
- Organisation-level branding (colors, logo, footer, reply-to)
- Per-type template overrides with {variable} substitution
- Email log with filtering by status, type, date range, recipient
- Preview and send-test endpoints for template management
- API endpoints: email-settings, email-templates (CRUD), email-logs (read-only)
- Integrated into existing flows: invitations, password reset, email
verification, registration approval/rejection
- 37 new tests across 4 test files, all existing tests updated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
|
||||
use App\Enums\EmailChangeStatus;
|
||||
use App\Enums\EmailTemplateType;
|
||||
use App\Mail\EmailChangedConfirmationMail;
|
||||
use App\Mail\VerifyEmailChangeMail;
|
||||
use App\Models\EmailChangeRequest;
|
||||
use App\Models\Person;
|
||||
use App\Models\User;
|
||||
@@ -17,6 +17,9 @@ use Illuminate\Validation\ValidationException;
|
||||
|
||||
final class EmailChangeService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EmailService $emailService,
|
||||
) {}
|
||||
/**
|
||||
* Request an email change. Sends verification to the NEW email.
|
||||
*/
|
||||
@@ -52,13 +55,17 @@ final class EmailChangeService
|
||||
]);
|
||||
|
||||
// Send verification email to the NEW address
|
||||
Mail::to($newEmail)->send(new VerifyEmailChangeMail(
|
||||
user: $user,
|
||||
newEmail: $newEmail,
|
||||
token: $plainToken,
|
||||
frontendUrl: $frontendUrl,
|
||||
requestedBy: $requestedBy,
|
||||
));
|
||||
$organisation = $user->organisations()->first();
|
||||
|
||||
$this->emailService->send(
|
||||
type: EmailTemplateType::EMAIL_VERIFICATION,
|
||||
recipientEmail: $newEmail,
|
||||
recipientName: $user->first_name . ' ' . $user->last_name,
|
||||
actionUrl: $frontendUrl . '/verify-email-change?token=' . $plainToken,
|
||||
organisation: $organisation,
|
||||
userId: $user->id,
|
||||
triggeredByUserId: $requestedBy->id,
|
||||
);
|
||||
|
||||
activity()
|
||||
->causedBy($requestedBy)
|
||||
|
||||
Reference in New Issue
Block a user