mail config data provider

This commit is contained in:
Yuri Kuznetsov
2025-02-12 13:35:19 +02:00
parent 8ba7fdfa85
commit a676f26c36
10 changed files with 86 additions and 24 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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 SendingAccountProvider
private 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 SendingAccountProvider
private function loadSystem(): void
{
$address = $this->config->get('outboundEmailFromAddress');
$address = $this->configDataProvider->getOutboundEmailFromAddress();
if (!$address) {
return;

View File

@@ -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 Account
public function getEmailAddress(): ?string
{
return $this->config->get('outboundEmailFromAddress');
return $this->configDataProvider->getOutboundEmailFromAddress();
}
public function getAssignedUser(): ?Link

View File

@@ -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');
}
}

View File

@@ -83,7 +83,8 @@ class Sender
private Log $log,
private TransportFactory $transportFactory,
private SendingAccountProvider $accountProvider,
private FileStorageManager $fileStorageManager
private FileStorageManager $fileStorageManager,
private ConfigDataProvider $configDataProvider,
) {
/** @noinspection PhpDeprecationInspection */
@@ -371,11 +372,11 @@ class Sender
if ($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 Sender
if (!$email->isNew()) {
/** @var Collection<Attachment> $relatedAttachmentCollection */
$relatedAttachmentCollection = $this->entityManager
->getRDBRepository(Email::ENTITY_TYPE)
->getRelation($email, 'attachments')
->find();

View File

@@ -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 SendingProcessor
private 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()) {

View File

@@ -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 AppService
private 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 = [];

View File

@@ -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 SettingsService
private 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);

View File

@@ -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 SendService
private 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;