From 918ae0ebc1be1486a7bcec72063dad8d34dee277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Thu, 12 Mar 2026 07:42:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[email]=20=ED=85=8C=EB=84=8C=ED=8A=B8?= =?UTF-8?q?=20=EB=A9=94=EC=9D=BC=20=EC=84=A4=EC=A0=95=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20=EB=B0=8F=20=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tenant_mail_configs 테이블 생성 (SMTP 설정, 브랜딩, 연결 테스트 결과) - mail_logs 테이블 생성 (발송 이력 추적) - TenantMailConfig, MailLog 모델 추가 (options JSON 정책 준수) --- app/Models/Tenants/MailLog.php | 47 ++++++++ app/Models/Tenants/TenantMailConfig.php | 103 ++++++++++++++++++ ...00000_create_tenant_mail_configs_table.php | 38 +++++++ ...26_03_12_100001_create_mail_logs_table.php | 34 ++++++ 4 files changed, 222 insertions(+) create mode 100644 app/Models/Tenants/MailLog.php create mode 100644 app/Models/Tenants/TenantMailConfig.php create mode 100644 database/migrations/2026_03_12_100000_create_tenant_mail_configs_table.php create mode 100644 database/migrations/2026_03_12_100001_create_mail_logs_table.php diff --git a/app/Models/Tenants/MailLog.php b/app/Models/Tenants/MailLog.php new file mode 100644 index 0000000..5bdde7f --- /dev/null +++ b/app/Models/Tenants/MailLog.php @@ -0,0 +1,47 @@ + 'datetime', + 'options' => 'array', + ]; + + public function tenant(): BelongsTo + { + return $this->belongsTo(Tenant::class); + } + + public function getOption(string $key, mixed $default = null): mixed + { + return data_get($this->options, $key, $default); + } + + public function setOption(string $key, mixed $value): static + { + $options = $this->options ?? []; + data_set($options, $key, $value); + $this->options = $options; + + return $this; + } +} diff --git a/app/Models/Tenants/TenantMailConfig.php b/app/Models/Tenants/TenantMailConfig.php new file mode 100644 index 0000000..ec842a3 --- /dev/null +++ b/app/Models/Tenants/TenantMailConfig.php @@ -0,0 +1,103 @@ + 'boolean', + 'daily_limit' => 'integer', + 'is_active' => 'boolean', + 'options' => 'array', + ]; + + // Options 키 상수 + public const OPTION_SMTP = 'smtp'; + + public const OPTION_PRESET = 'preset'; + + public const OPTION_BRANDING = 'branding'; + + public const OPTION_CONNECTION_TEST = 'connection_test'; + + public function tenant(): BelongsTo + { + return $this->belongsTo(Tenant::class); + } + + public function getOption(string $key, mixed $default = null): mixed + { + return data_get($this->options, $key, $default); + } + + public function setOption(string $key, mixed $value): static + { + $options = $this->options ?? []; + data_set($options, $key, $value); + $this->options = $options; + + return $this; + } + + public function getSmtpHost(): ?string + { + return $this->getOption('smtp.host'); + } + + public function getSmtpPort(): int + { + return (int) $this->getOption('smtp.port', 587); + } + + public function getSmtpEncryption(): string + { + return $this->getOption('smtp.encryption', 'tls'); + } + + public function getSmtpUsername(): ?string + { + return $this->getOption('smtp.username'); + } + + public function getSmtpPassword(): ?string + { + $encrypted = $this->getOption('smtp.password'); + if (! $encrypted) { + return null; + } + + try { + return decrypt($encrypted); + } catch (\Exception $e) { + return null; + } + } + + public function getPreset(): ?string + { + return $this->getOption('preset'); + } +} diff --git a/database/migrations/2026_03_12_100000_create_tenant_mail_configs_table.php b/database/migrations/2026_03_12_100000_create_tenant_mail_configs_table.php new file mode 100644 index 0000000..c1f40ce --- /dev/null +++ b/database/migrations/2026_03_12_100000_create_tenant_mail_configs_table.php @@ -0,0 +1,38 @@ +id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->string('provider', 20)->default('platform')->comment('발송 방식: platform, smtp, ses, mailgun'); + $table->string('from_address', 255)->comment('발신 이메일'); + $table->string('from_name', 255)->comment('발신자명'); + $table->string('reply_to', 255)->nullable()->comment('회신 주소'); + $table->boolean('is_verified')->default(false)->comment('도메인 검증 여부'); + $table->unsignedInteger('daily_limit')->default(500)->comment('일일 발송 한도'); + $table->boolean('is_active')->default(true)->comment('활성 여부'); + $table->json('options')->nullable()->comment('SMTP 설정, 브랜딩, 연결 테스트 결과'); + $table->unsignedBigInteger('created_by')->nullable()->comment('생성자'); + $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자'); + $table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자'); + $table->timestamps(); + $table->softDeletes(); + + $table->unique('tenant_id', 'uq_tenant_mail_configs'); + $table->index(['tenant_id', 'is_active']); + $table->foreign('tenant_id')->references('id')->on('tenants')->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::dropIfExists('tenant_mail_configs'); + } +}; diff --git a/database/migrations/2026_03_12_100001_create_mail_logs_table.php b/database/migrations/2026_03_12_100001_create_mail_logs_table.php new file mode 100644 index 0000000..a9a1aa7 --- /dev/null +++ b/database/migrations/2026_03_12_100001_create_mail_logs_table.php @@ -0,0 +1,34 @@ +id(); + $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID'); + $table->string('mailable_type', 100)->comment('Mailable 클래스명'); + $table->string('to_address', 255)->comment('수신자'); + $table->string('from_address', 255)->comment('발신자'); + $table->string('subject', 500)->comment('제목'); + $table->string('status', 20)->default('queued')->comment('상태: queued, sent, failed, bounced'); + $table->timestamp('sent_at')->nullable()->comment('발송 시각'); + $table->json('options')->nullable()->comment('에러 메시지, 재시도 횟수, 관련 모델'); + $table->timestamps(); + + $table->index(['tenant_id', 'status'], 'idx_mail_logs_tenant_status'); + $table->index(['tenant_id', 'created_at'], 'idx_mail_logs_tenant_date'); + $table->index(['tenant_id', 'mailable_type'], 'idx_mail_logs_mailable'); + $table->foreign('tenant_id')->references('id')->on('tenants')->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::dropIfExists('mail_logs'); + } +};