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

More SMTP options in config #1067 #1077

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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 app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ DB_PASSWORD="password"
SMTP_HOST="host.example.com"
SMTP_USER="relay@example.com"
SMTP_PASSWORD="password"
SMTP_PORT="587"
SMTP_AUTH="true"
SMTP_SECURE="tls"
6 changes: 3 additions & 3 deletions app/sprinkles/core/config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@
'mail' => [
'mailer' => 'smtp', // Set to one of 'smtp', 'mail', 'qmail', 'sendmail'
'host' => getenv('SMTP_HOST') ?: null,
'port' => 587,
'auth' => true,
'secure' => 'tls', // Enable TLS encryption. Set to `tls`, `ssl` or `false` (to disabled)
'port' => getenv('SMTP_PORT') ?: null,
'auth' => getenv('SMTP_AUTH') ?: null,
'secure' => getenv('SMTP_SECURE') ?: null, // Enable TLS encryption. Set to `tls`, `ssl` or `false` (to disabled)
Comment on lines +235 to +237
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum... This would create a breaking change for people without those settings already in their env, which push this change to UF 4.5. I wonder if there's a way to keep the default here, and overwrite in the env?

'username' => getenv('SMTP_USER') ?: null,
'password' => getenv('SMTP_PASSWORD') ?: null,
'smtp_debug' => 4,
Expand Down
28 changes: 24 additions & 4 deletions app/sprinkles/core/src/Bakery/SetupSmtpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ protected function configure()
->addOption('force', null, InputOption::VALUE_NONE, 'Force setup if SMTP appears to be already configured')
->addOption('smtp_host', null, InputOption::VALUE_OPTIONAL, 'The SMTP server hostname')
->addOption('smtp_user', null, InputOption::VALUE_OPTIONAL, 'The SMTP server user')
->addOption('smtp_password', null, InputOption::VALUE_OPTIONAL, 'The SMTP server password');
->addOption('smtp_password', null, InputOption::VALUE_OPTIONAL, 'The SMTP server password')
->addOption('smtp_port', null, InputOption::VALUE_OPTIONAL, 'The SMTP server port')
->addOption('smtp_auth', null, InputOption::VALUE_OPTIONAL, 'The SMTP server authentication')
->addOption('smtp_secure', null, InputOption::VALUE_OPTIONAL, 'The SMTP server security type');
}

/**
Expand Down Expand Up @@ -89,13 +92,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
'SMTP_HOST' => ($dotenvEditor->keyExists('SMTP_HOST')) ? $dotenvEditor->getValue('SMTP_HOST') : '',
'SMTP_USER' => ($dotenvEditor->keyExists('SMTP_USER')) ? $dotenvEditor->getValue('SMTP_USER') : '',
'SMTP_PASSWORD' => ($dotenvEditor->keyExists('SMTP_PASSWORD')) ? $dotenvEditor->getValue('SMTP_PASSWORD') : '',
'SMTP_PORT' => ($dotenvEditor->keyExists('SMTP_PORT')) ? $dotenvEditor->getValue('SMTP_PORT') : '',
'SMTP_AUTH' => ($dotenvEditor->keyExists('SMTP_AUTH')) ? $dotenvEditor->getValue('SMTP_AUTH') : '',
'SMTP_SECURE' => ($dotenvEditor->keyExists('SMTP_SECURE')) ? $dotenvEditor->getValue('SMTP_SECURE') : '',
];

// There may be some custom config or global env values defined on the server.
// We'll check for that and ask for confirmation in this case.
if ($config['mail.host'] != $keys['SMTP_HOST'] ||
$config['mail.username'] != $keys['SMTP_USER'] ||
$config['mail.password'] != $keys['SMTP_PASSWORD']) {
$config['mail.password'] != $keys['SMTP_PASSWORD'] ||
$config['mail.port'] != $keys['SMTP_PORT'] ||
$config['mail.auth'] != $keys['SMTP_AUTH'] ||
$config['mail.secure'] != $keys['SMTP_SECURE']) {
$this->io->warning("Current SMTP configuration differ from the configuration defined in `{$this->envPath}`. Global system environment variables might be defined.");

if (!$this->io->confirm('Continue?', false)) {
Expand Down Expand Up @@ -130,7 +139,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
protected function askForSmtpMethod(InputInterface $input)
{
// If the user defined any of the command input argument, skip right to SMTP method
if ($input->getOption('smtp_host') || $input->getOption('smtp_user') || $input->getOption('smtp_password')) {
if ($input->getOption('smtp_host') || $input->getOption('smtp_user') || $input->getOption('smtp_password')
|| $input->getOption('smtp_port') || $input->getOption('smtp_auth') || $input->getOption('smtp_secure')) {
return $this->askForSmtp($input);
}

Expand Down Expand Up @@ -169,11 +179,17 @@ protected function askForSmtp(InputInterface $input)
// Use custom validator to accept empty password
return $password;
});
$smtpPort = ($input->getOption('smtp_port')) ?: $this->io->ask('SMTP Server Port', 587);
$smtpAuth = ($input->getOption('smtp_auth')) ?: $this->io->ask('SMTP Server Authentication', 'true');
$smtpSecure = ($input->getOption('smtp_secure')) ?: $this->io->ask('SMTP Server Security type', 'tls');
Comment on lines +183 to +184
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A yes/no question or choices could probably better here.


return [
'SMTP_HOST' => $smtpHost,
'SMTP_USER' => $smtpUser,
'SMTP_PASSWORD' => $smtpPassword,
'SMTP_PORT' => $smtpPort,
'SMTP_AUTH' => $smtpAuth,
'SMTP_SECURE' => $smtpSecure,
];
}

Expand Down Expand Up @@ -216,6 +232,9 @@ protected function askForNone(InputInterface $input)
'SMTP_HOST' => '',
'SMTP_USER' => '',
'SMTP_PASSWORD' => '',
'SMTP_PORT' => '',
'SMTP_AUTH' => '',
'SMTP_SECURE' => '',
];
} else {
$this->askForSmtpMethod($input);
Expand All @@ -231,7 +250,8 @@ protected function askForNone(InputInterface $input)
*/
protected function isSmtpConfigured(DotenvEditor $dotenvEditor)
{
if ($dotenvEditor->keyExists('SMTP_HOST') && $dotenvEditor->keyExists('SMTP_USER') && $dotenvEditor->keyExists('SMTP_PASSWORD')) {
if ($dotenvEditor->keyExists('SMTP_HOST') && $dotenvEditor->keyExists('SMTP_USER') && $dotenvEditor->keyExists('SMTP_PASSWORD')
&& $dotenvEditor->keyExists('SMTP_PORT') && $dotenvEditor->keyExists('SMTP_AUTH') && $dotenvEditor->keyExists('SMTP_SECURE')) {
return true;
} else {
return false;
Expand Down