EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
mail config data provider
Yuri Kuznetsova676f26c36a8
diff --git a/application/Espo/Classes/FieldProcessing/InboundEmail/IsSystemLoader.php b/application/Espo/Classes/FieldProcessing/InboundEmail/IsSystemLoader.phpindex b943bb1d37..a2ea493fc8 100644--- a/application/Espo/Classes/FieldProcessing/InboundEmail/IsSystemLoader.php+++ b/application/Espo/Classes/FieldProcessing/InboundEmail/IsSystemLoader.php@@ -31,7 +31,7 @@ namespace Espo\Classes\FieldProcessing\InboundEmail;use Espo\Core\FieldProcessing\Loader;use Espo\Core\FieldProcessing\Loader\Params;-use Espo\Core\Utils\Config;+use Espo\Core\Mail\ConfigDataProvider;use Espo\Entities\InboundEmail;use Espo\ORM\Entity;@@ -41,12 +41,12 @@ use Espo\ORM\Entity;class IsSystemLoader implements Loader{public function __construct(- private Config $config,+ private ConfigDataProvider $configDataProvider,) {}public function process(Entity $entity, Params $params): void{- $isSystem = $entity->getEmailAddress() === $this->config->get('outboundEmailFromAddress');+ $isSystem = $entity->getEmailAddress() === $this->configDataProvider->getOutboundEmailFromAddress();$entity->set('isSystem', $isSystem);}diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/SendType.php b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/SendType.phpindex 59ec405473..d6abc70dfa 100644--- a/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/SendType.php+++ b/application/Espo/Core/Formula/Functions/ExtGroup/EmailGroup/SendType.php@@ -30,6 +30,7 @@namespace Espo\Core\Formula\Functions\ExtGroup\EmailGroup;use Espo\Core\ApplicationUser;+use Espo\Core\Mail\ConfigDataProvider;use Espo\Core\ORM\Repository\Option\SaveOption;use Espo\Core\Formula\ArgumentList;use Espo\Core\Formula\Functions\BaseFunction;@@ -99,7 +100,9 @@ class SendType extends BaseFunction implements}if (!$email->get('from')) {- $from = $this->config->get('outboundEmailFromAddress');+ $from = $this->injectableFactory+ ->create(ConfigDataProvider::class)+ ->getOutboundEmailFromAddress();if ($from) {$email->set('from', $from);diff --git a/application/Espo/Core/Mail/Account/SendingAccountProvider.php b/application/Espo/Core/Mail/Account/SendingAccountProvider.phpindex 2f15e862af..602c0624df 100644--- a/application/Espo/Core/Mail/Account/SendingAccountProvider.php+++ b/application/Espo/Core/Mail/Account/SendingAccountProvider.php@@ -34,6 +34,7 @@ use Espo\Core\AclManager;use Espo\Core\Exceptions\Error;use Espo\Core\Mail\Account\GroupAccount\AccountFactory as GroupAccountFactory;use Espo\Core\Mail\Account\PersonalAccount\AccountFactory as PersonalAccountFactory;+use Espo\Core\Mail\ConfigDataProvider;use Espo\Core\Name\Field;use Espo\Core\Utils\Config;use Espo\Entities\EmailAccount as EmailAccountEntity;@@ -56,7 +57,8 @@ class SendingAccountProviderprivate GroupAccountFactory $groupAccountFactory,private PersonalAccountFactory $personalAccountFactory,private AclManager $aclManager,- private SystemSettingsAccount $systemSettingsAccount+ private SystemSettingsAccount $systemSettingsAccount,+ private ConfigDataProvider $configDataProvider,) {}public function getShared(User $user, string $emailAddress): ?Account@@ -214,7 +216,7 @@ class SendingAccountProviderprivate function loadSystem(): void{- $address = $this->config->get('outboundEmailFromAddress');+ $address = $this->configDataProvider->getOutboundEmailFromAddress();if (!$address) {return;diff --git a/application/Espo/Core/Mail/Account/SystemSettingsAccount.php b/application/Espo/Core/Mail/Account/SystemSettingsAccount.phpindex 5ff109ddb2..90a53596b8 100644--- a/application/Espo/Core/Mail/Account/SystemSettingsAccount.php+++ b/application/Espo/Core/Mail/Account/SystemSettingsAccount.php@@ -33,6 +33,7 @@ use Espo\Core\Field\Date;use Espo\Core\Field\DateTime;use Espo\Core\Field\Link;use Espo\Core\Field\LinkMultiple;+use Espo\Core\Mail\ConfigDataProvider;use Espo\Core\Mail\Exceptions\NoSmtp;use Espo\Core\Mail\SmtpParams;use Espo\Core\Utils\Config;@@ -41,8 +42,10 @@ use Espo\Entities\Settings;class SystemSettingsAccount implements Account{- public function __construct(private Config $config)- {}+ public function __construct(+ private Config $config,+ private ConfigDataProvider $configDataProvider,+ ) {}public function updateFetchData(FetchData $fetchData): void {}@@ -68,7 +71,7 @@ class SystemSettingsAccount implements Accountpublic function getEmailAddress(): ?string{- return $this->config->get('outboundEmailFromAddress');+ return $this->configDataProvider->getOutboundEmailFromAddress();}public function getAssignedUser(): ?Linkdiff --git a/application/Espo/Core/Mail/ConfigDataProvider.php b/application/Espo/Core/Mail/ConfigDataProvider.phpnew file mode 100644index 0000000000..1c8f8eee54--- /dev/null+++ b/application/Espo/Core/Mail/ConfigDataProvider.php@@ -0,0 +1,44 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Mail;++use Espo\Core\Utils\Config;++class ConfigDataProvider+{+ public function __construct(+ private Config $config,+ ) {}++ public function getOutboundEmailFromAddress(): ?string+ {+ return $this->config->get('outboundEmailFromAddress');+ }+}diff --git a/application/Espo/Core/Mail/Sender.php b/application/Espo/Core/Mail/Sender.phpindex 549acbc692..010cbb03f7 100644--- a/application/Espo/Core/Mail/Sender.php+++ b/application/Espo/Core/Mail/Sender.php@@ -83,7 +83,8 @@ class Senderprivate Log $log,private TransportFactory $transportFactory,private SendingAccountProvider $accountProvider,- private FileStorageManager $fileStorageManager+ private FileStorageManager $fileStorageManager,+ private ConfigDataProvider $configDataProvider,) {/** @noinspection PhpDeprecationInspection */@@ -371,11 +372,11 @@ class Senderif ($fromAddress) {$fromAddress = trim($fromAddress);} else {- if (empty($params['fromAddress']) && !$config->get('outboundEmailFromAddress')) {+ if (empty($params['fromAddress']) && !$this->configDataProvider->getOutboundEmailFromAddress()) {throw new NoSmtp('outboundEmailFromAddress is not specified in config.');}- $fromAddress = $params['fromAddress'] ?? $config->get('outboundEmailFromAddress');+ $fromAddress = $params['fromAddress'] ?? $this->configDataProvider->getOutboundEmailFromAddress();$email->setFromAddress($fromAddress);}@@ -415,7 +416,6 @@ class Senderif (!$email->isNew()) {/** @var Collection<Attachment> $relatedAttachmentCollection */$relatedAttachmentCollection = $this->entityManager- ->getRDBRepository(Email::ENTITY_TYPE)->getRelation($email, 'attachments')->find();diff --git a/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php b/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.phpindex aa7d1279b1..17e666f992 100644--- a/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php+++ b/application/Espo/Modules/Crm/Tools/MassEmail/SendingProcessor.php@@ -29,6 +29,7 @@namespace Espo\Modules\Crm\Tools\MassEmail;+use Espo\Core\Mail\ConfigDataProvider;use Espo\ORM\EntityCollection;use Laminas\Mail\Message;@@ -80,7 +81,8 @@ class SendingProcessorprivate AccountFactory $accountFactory,private CampaignService $campaignService,private MessageHeadersPreparator $headersPreparator,- private TemplateProcessor $templateProcessor+ private TemplateProcessor $templateProcessor,+ private ConfigDataProvider $configDataProvider,) {}/**@@ -528,7 +530,7 @@ class SendingProcessor$senderParams = $senderParams->withFromAddress($massEmail->getFromAddress() ??- $this->config->get('outboundEmailFromAddress')+ $this->configDataProvider->getOutboundEmailFromAddress());if ($massEmail->getFromName()) {diff --git a/application/Espo/Tools/App/AppService.php b/application/Espo/Tools/App/AppService.phpindex 4e00464fdb..f8f053aee3 100644--- a/application/Espo/Tools/App/AppService.php+++ b/application/Espo/Tools/App/AppService.php@@ -30,6 +30,7 @@namespace Espo\Tools\App;use Espo\Core\Authentication\Util\MethodProvider as AuthenticationMethodProvider;+use Espo\Core\Mail\ConfigDataProvider as EmailConfigDataProvider;use Espo\Core\Name\Field;use Espo\Core\Utils\SystemUser;use Espo\Entities\DashboardTemplate;@@ -73,7 +74,8 @@ class AppServiceprivate FieldUtil $fieldUtil,private Log $log,private AuthenticationMethodProvider $authenticationMethodProvider,- private SystemUser $systemUser+ private SystemUser $systemUser,+ private EmailConfigDataProvider $emailConfigDataProvider,) {}/**@@ -256,7 +258,7 @@ class AppService$user = $this->user;$outboundEmailIsShared = $this->config->get('outboundEmailIsShared');- $outboundEmailFromAddress = $this->config->get('outboundEmailFromAddress');+ $outboundEmailFromAddress = $this->emailConfigDataProvider->getOutboundEmailFromAddress();$emailAddressList = [];$userEmailAddressList = [];diff --git a/application/Espo/Tools/App/SettingsService.php b/application/Espo/Tools/App/SettingsService.phpindex bb0d726c3a..f12906b71e 100644--- a/application/Espo/Tools/App/SettingsService.php+++ b/application/Espo/Tools/App/SettingsService.php@@ -29,6 +29,7 @@namespace Espo\Tools\App;+use Espo\Core\Mail\ConfigDataProvider as EmailConfigDataProvider;use Espo\Core\Utils\ThemeManager;use Espo\Entities\Settings;use Espo\ORM\Entity;@@ -70,6 +71,7 @@ class SettingsServiceprivate AuthenticationMethodProvider $authenticationMethodProvider,private ThemeManager $themeManager,private Config\SystemConfig $systemConfig,+ private EmailConfigDataProvider $emailConfigDataProvider,) {}/**@@ -251,7 +253,10 @@ class SettingsService}if (- ($this->config->get('outboundEmailFromAddress') || $this->config->get('internalSmtpServer')) &&+ (+ $this->emailConfigDataProvider->getOutboundEmailFromAddress() ||+ $this->config->get('internalSmtpServer')+ ) &&!$this->config->get('passwordRecoveryDisabled')) {$data->passwordRecoveryEnabled = true;@@ -280,9 +285,9 @@ class SettingsService}}- if ($this->isRestrictedMode() && !$user->isSuperAdmin()) {+ /*if ($this->isRestrictedMode() && !$user->isSuperAdmin()) {// @todo Maybe add restriction level for non-super admins.- }+ }*/foreach ($ignoreItemList as $item) {unset($data->$item);diff --git a/application/Espo/Tools/Email/SendService.php b/application/Espo/Tools/Email/SendService.phpindex 26fe46805f..00fc90dc30 100644--- a/application/Espo/Tools/Email/SendService.php+++ b/application/Espo/Tools/Email/SendService.php@@ -44,6 +44,7 @@ use Espo\Core\Mail\Account\PersonalAccount\Account as PersonalAccount;use Espo\Core\Mail\Account\PersonalAccount\AccountFactory as PersonalAccountFactory;use Espo\Core\Mail\Account\PersonalAccount\Service as PersonalAccountService;use Espo\Core\Mail\Account\SendingAccountProvider;+use Espo\Core\Mail\ConfigDataProvider;use Espo\Core\Mail\EmailSender;use Espo\Core\Mail\Exceptions\NoSmtp;use Espo\Core\Mail\Exceptions\SendingError;@@ -96,7 +97,8 @@ class SendServiceprivate GroupAccountService $groupAccountService,private HandlerProcessor $handlerProcessor,private PersonalAccountFactory $personalAccountFactory,- private GroupAccountFactory $groupAccountFactory+ private GroupAccountFactory $groupAccountFactory,+ private ConfigDataProvider $configDataProvider,) {}/**@@ -126,7 +128,7 @@ class SendService$systemIsShared = $this->config->get('outboundEmailIsShared');$systemFromName = $this->config->get('outboundEmailFromName');- $systemFromAddress = $this->config->get('outboundEmailFromAddress');+ $systemFromAddress = $this->configDataProvider->getOutboundEmailFromAddress();$emailSender = $this->emailSender->create();@@ -136,7 +138,6 @@ class SendService// @todo Use getEmailAddressGroup./** @var Collection<EmailAddress> $emailAddressCollection */$emailAddressCollection = $this->entityManager- ->getRDBRepositoryByClass(User::class)->getRelation($user, 'emailAddresses')->find();@@ -154,7 +155,7 @@ class SendService$fromAddress = strtolower($originalFromAddress);$isUserAddress = in_array($fromAddress, $userAddressList);- $isSystemAddress = $fromAddress === strtolower($systemFromAddress);+ $isSystemAddress = $fromAddress === strtolower($systemFromAddress ?? '');$smtpParams = null;$personalAccount = null;