diff --git a/app/Models/MailAccount.php b/app/Models/MailAccount.php new file mode 100644 index 0000000..55e7dc4 --- /dev/null +++ b/app/Models/MailAccount.php @@ -0,0 +1,45 @@ + 'encrypted:array', + 'enabled' => 'boolean', + ]; + + public function buildTransport(): TransportInterface + { + if ($this->type === 'azure') { + $config = array_merge($this->config, [ + 'from_address' => $this->from_address, + 'graph_api_version' => 'v1.0', + 'timeout' => 30, + 'save_to_sent_items' => false, + ]); + return new AzureTransport( + new GraphClient(new TokenManager($config), $config), + $config + ); + } + + $cfg = $this->config; + $tls = ($cfg['encryption'] ?? 'tls') === 'ssl'; + $transport = new EsmtpTransport($cfg['host'], (int) ($cfg['port'] ?? 587), $tls); + if (!empty($cfg['username'])) { + $transport->setUsername($cfg['username']); + $transport->setPassword($cfg['password'] ?? ''); + } + return $transport; + } +} diff --git a/database/migrations/2026_05_26_000001_create_mail_accounts_table.php b/database/migrations/2026_05_26_000001_create_mail_accounts_table.php new file mode 100644 index 0000000..c7213c1 --- /dev/null +++ b/database/migrations/2026_05_26_000001_create_mail_accounts_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name', 100)->unique(); + $table->string('label', 150); + $table->enum('type', ['azure', 'smtp']); + $table->string('from_address', 255); + $table->string('from_name', 150)->nullable(); + $table->text('config'); + $table->boolean('enabled')->default(true); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('mail_accounts'); + } +};