diff --git a/app/controller/admin.php b/app/controller/admin.php index cebe6ac..3740427 100644 --- a/app/controller/admin.php +++ b/app/controller/admin.php @@ -30,6 +30,7 @@ class AdminController extends BaseController { $user = UserModel::getAuthUser(); $locs = LocationsModel::getAll(false); $user_accounts = UserModel::getAll(); + $mail_encryption_types = AppModel::getMailEncryptionTypes(); $new_version = null; $current_version = null; @@ -49,6 +50,7 @@ class AdminController extends BaseController { 'user' => $user, 'locations' => $locs, 'user_accounts' => $user_accounts, + 'mail_encryption_types' => $mail_encryption_types, 'new_version' => $new_version, 'current_version' => $current_version ]); diff --git a/app/controller/api.php b/app/controller/api.php index 830e9ff..f6ee78c 100644 --- a/app/controller/api.php +++ b/app/controller/api.php @@ -46,6 +46,7 @@ class ApiController extends BaseController { $mailobj->setRecipient($user->get('email')); $mailobj->setSubject(__('app.mail_share_photo_title')); $mailobj->setView('mail/share_photo', [], ['url_photo' => $result->data->url, 'url_removal' => env('APP_SERVICE_URL') . '/api/photo/remove?ident=' . $result->data->ident . '&ret=home']); + $mailobj->setProperties(mail_properties()); $mailobj->send(); return json([ diff --git a/app/controller/cronjobs.php b/app/controller/cronjobs.php index 7afd627..0b31466 100644 --- a/app/controller/cronjobs.php +++ b/app/controller/cronjobs.php @@ -20,6 +20,8 @@ class CronjobsController extends BaseController { http_response_code(403); exit(); } + + app_mail_config(); } /** diff --git a/app/helper/AppHelper.php b/app/helper/AppHelper.php index d9e7816..7203774 100644 --- a/app/helper/AppHelper.php +++ b/app/helper/AppHelper.php @@ -21,4 +21,23 @@ function app_mail_config() $_ENV['SMTP_USERNAME'] = app('smtp_username'); $_ENV['SMTP_PASSWORD'] = app('smtp_password'); $_ENV['SMTP_ENCRYPTION'] = app('smtp_encryption'); +} + +/** + * @return array + */ +function mail_properties() +{ + $result = []; + + if ($_ENV['SMTP_ENCRYPTION'] === 'none') { + $_ENV['SMTP_ENCRYPTION'] = 'tls'; + + $result = [ + 'SMTPSecure' => false, + 'SMTPAutoTLS' => false + ]; + } + + return $result; } \ No newline at end of file diff --git a/app/models/AppModel.php b/app/models/AppModel.php index 657390b..13e8326 100644 --- a/app/models/AppModel.php +++ b/app/models/AppModel.php @@ -72,4 +72,16 @@ class AppModel extends \Asatru\Database\Model { throw $e; } } + + /** + * @return array + */ + public static function getMailEncryptionTypes() + { + return [ + 'none', + PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS, + PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS + ]; + } } \ No newline at end of file diff --git a/app/models/TaskInformerModel.php b/app/models/TaskInformerModel.php index b7011ca..9fd85a2 100644 --- a/app/models/TaskInformerModel.php +++ b/app/models/TaskInformerModel.php @@ -52,6 +52,7 @@ class TaskInformerModel extends \Asatru\Database\Model { $mailobj->setRecipient($user->get('email')); $mailobj->setSubject(__('app.mail_info_task_' . $what)); $mailobj->setView('mail/task_' . $what, [], ['task' => $task, 'user' => $user]); + $mailobj->setProperties(mail_properties()); $mailobj->send(); static::raw('INSERT INTO `' . self::tableName() . '` (user, task, what) VALUES(?, ?, ?)', [$user->get('id'), $task->get('id'), $what]); diff --git a/app/models/UserModel.php b/app/models/UserModel.php index 671ae9a..4a6ba9d 100644 --- a/app/models/UserModel.php +++ b/app/models/UserModel.php @@ -105,6 +105,7 @@ class UserModel extends \Asatru\Database\Model { $mailobj->setRecipient($email); $mailobj->setSubject(__('app.reset_password')); $mailobj->setView('mail/mailreset', [], ['workspace' => app('workspace'), 'token' => $reset_token]); + $mailobj->setProperties(mail_properties()); $mailobj->send(); } catch (\Exception $e) { throw $e; @@ -445,6 +446,7 @@ class UserModel extends \Asatru\Database\Model { $mailobj->setRecipient($email); $mailobj->setSubject(__('app.account_created')); $mailobj->setView('mail/mailacccreated', [], ['workspace' => app('workspace'), 'password' => $password]); + $mailobj->setProperties(mail_properties()); $mailobj->send(); } catch (\Exception $e) { throw $e; diff --git a/app/views/admin.php b/app/views/admin.php index f678012..4e31252 100644 --- a/app/views/admin.php +++ b/app/views/admin.php @@ -292,7 +292,11 @@