Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failover transport to MailSetting #1315

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/system/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
'search' => 'Search',
],
'mail' => [
'failover' => 'Failover',
'failover_mailers' => 'Failover transports to use',
'failover_mailers_placeholer' => 'Pick transports to use',
'log_file' => 'Log file',
'menu_label' => 'Mail configuration',
'menu_description' => 'Manage email configuration.',
Expand Down
12 changes: 12 additions & 0 deletions modules/system/models/MailSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MailSetting extends Model
{
use \Winter\Storm\Database\Traits\Validation;

const MODE_FAILOVER = 'failover';
const MODE_LOG = 'log';
const MODE_MAIL = 'mail';
const MODE_SENDMAIL = 'sendmail';
Expand Down Expand Up @@ -72,9 +73,16 @@ public function initSettingsData()
$this->smtp_authorization = !!strlen($this->smtp_user);
}

public function getFailoverMailersOptions()
{
$config = App::make('config');
return array_keys($config->get('mail.mailers'));
}

public function getSendModeOptions()
{
return [
static::MODE_FAILOVER => 'system::lang.mail.failover',
static::MODE_LOG => 'system::lang.mail.log_file',
static::MODE_MAIL => 'system::lang.mail.php_mail',
static::MODE_SENDMAIL => 'system::lang.mail.sendmail',
Expand All @@ -91,6 +99,10 @@ public static function applyConfigValues()
$config->set('mail.from.address', $settings->sender_email);

switch ($settings->send_mode) {
case self::MODE_FAILOVER:
$config->set('mail.mailers.failover.mailers', explode(',', $settings->failover_mailers) ?? ['log']);
break;

case self::MODE_SMTP:
$config->set('mail.mailers.smtp.host', $settings->smtp_address);
$config->set('mail.mailers.smtp.port', $settings->smtp_port);
Expand Down
8 changes: 8 additions & 0 deletions modules/system/models/mailsetting/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ tabs:
field: send_mode
condition: value[sendmail]

failover_mailers:
label: system::lang.mail.failover_mailers
placeholder: system::lang.mail.failover_mailers_placeholer
type: taglist
options: getFailoverMailersOptions
customTags: false
tab: system::lang.mail.general

_send_test:
type: partial
path: ~/modules/system/models/mailsetting/_send_test_button.php
Expand Down
Loading