Skip to content

Commit

Permalink
Merge pull request #1406 from bakaphp/hotfix-email-provider
Browse files Browse the repository at this point in the history
Merge pull request #1358 from bakaphp/development
  • Loading branch information
kaioken committed May 29, 2024
2 parents 037003f + 85a3ae9 commit 20946cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Baka\Contracts\AppInterface;
use Baka\Contracts\CompanyInterface;
use Baka\Contracts\HashTableInterface;
use Illuminate\Support\Facades\Config;

class SmtpRuntimeConfiguration
{
Expand All @@ -24,31 +25,38 @@ public function __construct(
/**
* Load SMTP settings from the given source.
*/
protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): void
protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): string
{
config([
"mail.mailers.{$provider}.host" => $source->get('smtp_host'),
"mail.mailers.{$provider}.port" => $source->get('smtp_port'),
"mail.mailers.{$provider}.username" => $source->get('smtp_username'),
"mail.mailers.{$provider}.password" => $source->get('smtp_password'),
"mail.mailers.{$provider}.encryption" => $source->get('smtp_encryption') ?? 'tls'
]);
$config = [
'transport' => 'smtp',
'host' => $source->get('smtp_host'),
'port' => $source->get('smtp_port'),
'encryption' => $source->get('smtp_encryption') ?? 'tls',
'username' => $source->get('smtp_username'),
'password' => $source->get('smtp_password'),
'timeout' => null,
];

Config::set('mail.mailers.' . $provider, $config);

return $provider;
}


/**
* Load SMTP settings from the app.
*/
protected function loadAppSettings(): void
protected function loadAppSettings(): string
{
$this->loadSmtpSettingsFromSource($this->appSmtp, $this->app);
return $this->loadSmtpSettingsFromSource($this->appSmtp, $this->app);
}

/**
* Load SMTP settings from the company config.
*/
protected function loadCompanySettings(): void
protected function loadCompanySettings(): string
{
$this->loadSmtpSettingsFromSource($this->companySmtp, $this->company);
return $this->loadSmtpSettingsFromSource($this->companySmtp, $this->company);
}

/**
Expand All @@ -58,13 +66,9 @@ protected function loadCompanySettings(): void
public function loadSmtpSettings(): string
{
if ($this->company !== null && $this->company->get('smtp_host')) {
$this->loadCompanySettings();

return $this->companySmtp;
return $this->loadCompanySettings();
} elseif ($this->app->get('smtp_host')) {
$this->loadAppSettings();

return $this->appSmtp;
return $this->loadAppSettings();
}

return $this->defaultSmtp;
Expand All @@ -77,8 +81,8 @@ public function getFromEmail(): array
{
if ($this->company !== null && $this->company->get('from_email_address')) {
return [
'name' => $this->company->get('from_email_name'),
'address' => $this->company->get('from_email_address'),
'name' => $this->company->get('from_email_name') ?? config('mail.from.name'),
'address' => $this->company->get('from_email_address') ?? config('mail.from.address'),
];
}

Expand Down
1 change: 1 addition & 0 deletions src/Kanvas/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Notification extends LaravelNotification implements EmailInterfaces, Shoul
protected ?UserInterface $fromUser = null;
protected ?UserInterface $toUser = null;
protected ?CompanyInterface $company = null;
public ?array $pathAttachment = null;

public array $channels = [
'mail',
Expand Down

0 comments on commit 20946cc

Please sign in to comment.