From 9718506b3b62058bdd973fe86933d16f37868ff1 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Wed, 25 Sep 2024 14:45:04 +0300 Subject: [PATCH] update --- .../Email/App/Console/SetupEmailServer.php | 4 ++++ .../Email/App/Filament/Pages/EmailSettings.php | 7 +++++++ .../Email/App/Filament/Pages/SendEmail.php | 11 +++++++++-- .../App/Filament/Resources/EmailBoxResource.php | 7 ++++--- web/Modules/Email/shell/install.sh | 15 ++++++++------- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/web/Modules/Email/App/Console/SetupEmailServer.php b/web/Modules/Email/App/Console/SetupEmailServer.php index 533f4fe..e8005b5 100644 --- a/web/Modules/Email/App/Console/SetupEmailServer.php +++ b/web/Modules/Email/App/Console/SetupEmailServer.php @@ -55,6 +55,10 @@ class SetupEmailServer extends Command 'database' => PhyreConfig::get('DB_DATABASE'), ]; + if (!is_dir('/etc/postfix/sql')) { + mkdir('/etc/postfix/sql'); + } + $postfixMysqlVirtualAliasMapsCf = PhyreBlade::render('email::server.postfix.sql.mysql_virtual_alias_maps.cf',$mysqlDbDetails); file_put_contents('/etc/postfix/sql/mysql_virtual_alias_maps.cf', $postfixMysqlVirtualAliasMapsCf); diff --git a/web/Modules/Email/App/Filament/Pages/EmailSettings.php b/web/Modules/Email/App/Filament/Pages/EmailSettings.php index cfde0fc..44c364d 100644 --- a/web/Modules/Email/App/Filament/Pages/EmailSettings.php +++ b/web/Modules/Email/App/Filament/Pages/EmailSettings.php @@ -19,6 +19,13 @@ class EmailSettings extends BaseSettings protected static ?int $navigationSort = 4; + public function save() : void + { + parent::save(); + + \Artisan::call('email:setup-email-server'); + + } public function schema(): array { diff --git a/web/Modules/Email/App/Filament/Pages/SendEmail.php b/web/Modules/Email/App/Filament/Pages/SendEmail.php index 1302889..5b0f215 100644 --- a/web/Modules/Email/App/Filament/Pages/SendEmail.php +++ b/web/Modules/Email/App/Filament/Pages/SendEmail.php @@ -29,9 +29,14 @@ Welcome to your new account. '; public $subject = 'Welcome'; + public function getEmailDomain() + { + return setting('email.domain'); + } + public function form(Form $form): Form { - $this->from = 'admin@'; + $this->from = 'admin@'.$this->getEmailDomain(); return $form ->schema([ @@ -57,9 +62,11 @@ Welcome to your new account. public function send() { + $emailDomain = $this->getEmailDomain(); + $phpMailer = new PHPMailer(); $phpMailer->isMail(); - $phpMailer->setFrom('admin@allsidepixels.com', 'admin@allsidepixels.com'); + $phpMailer->setFrom('admin@' . $emailDomain, 'admin@'.$emailDomain); $phpMailer->addAddress($this->to); $phpMailer->Subject = $this->subject; $phpMailer->Body = $this->body; diff --git a/web/Modules/Email/App/Filament/Resources/EmailBoxResource.php b/web/Modules/Email/App/Filament/Resources/EmailBoxResource.php index 1aa846d..8e0ed27 100644 --- a/web/Modules/Email/App/Filament/Resources/EmailBoxResource.php +++ b/web/Modules/Email/App/Filament/Resources/EmailBoxResource.php @@ -34,9 +34,10 @@ class EmailBoxResource extends Resource Forms\Components\TextInput::make('username') ->label('Username') ->disabled(function ($record) { - return $record->exists; - }) - ->columnSpanFull(), + if ($record) { + return $record->exists; + } + })->columnSpanFull(), Forms\Components\Select::make('domain') ->label('Domain') diff --git a/web/Modules/Email/shell/install.sh b/web/Modules/Email/shell/install.sh index e54d05f..2444a5b 100644 --- a/web/Modules/Email/shell/install.sh +++ b/web/Modules/Email/shell/install.sh @@ -1,11 +1,12 @@ sudo apt-get update -y -sudo apt-get install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql dovecot-sieve dovecot-managesieved -y -sudo apt-get install postfix postfix-mysql -y -sudo apt-get install mailutils -y -sudo apt-get install opendkim opendkim-tools -y -sudo apt-get install spamassassin spamc -y -sudo apt-get install clamav clamav-daemon -y -sudo apt-get install amavisd-new -y + +sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql dovecot-sieve dovecot-managesieved -yq +sudo DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install postfix postfix-mysql -yq +sudo apt-get --no-install-recommends install mailutils -yq +sudo apt-get --no-install-recommends install opendkim opendkim-tools -yq +sudo apt-get --no-install-recommends install spamassassin spamc -yq +sudo apt-get --no-install-recommends install clamav clamav-daemon -yq +sudo apt-get --no-install-recommends install amavisd-new -yq # Enable email ports ufw allow 25