@creativologist
Background (8.x Architecture)
In SuiteCRM 8+, outbound email accounts are managed through the service layer, mainly in:
core/backend/OutboundEmail/Service/OutboundEmailConfigurationService.php
The dropdown of âFromâ addresses in the email composer is built using the method:
OutboundEmailConfigurationService::getUserConfigurations()
That method aggregates:
- User accounts
- Group accounts
- System account(s)
âŚbut does not always check $currentUser->is_admin.
Strategy
Weâll create a custom extension to override or decorate the OutboundEmailConfigurationService so that:
- If the user is not admin, we remove any configuration whose type is
system.
File Structure
Create this file in your instance:
extensions/custom/OutboundEmail/Service/CustomOutboundEmailConfigurationService.php
`
(If /extensions/custom/OutboundEmail/Service/ doesnât exist, create the directories.)
Patch Code
Step 1
<?php
namespace App\Extensions\Custom\OutboundEmail\Service;
use SuiteCRM\Core\OutboundEmail\Service\OutboundEmailConfigurationService;
use SuiteCRM\Core\OutboundEmail\Entity\OutboundEmailConfiguration;
use SuiteCRM\Core\User\User;
/**
* Custom service to filter system outbound accounts for non-admin users
*/
class CustomOutboundEmailConfigurationService extends OutboundEmailConfigurationService
{
/**
* Override to remove system outbound accounts for non-admin users
*/
public function getUserConfigurations(User $currentUser): array
{
$configs = parent::getUserConfigurations($currentUser);
if (!$currentUser->isAdmin()) {
$configs = array_filter($configs, function (OutboundEmailConfiguration $config) {
$type = $config->getType(); // usually: 'system', 'group', or 'user'
return $type !== 'system';
});
}
return array_values($configs); // reindex array
}
}
Step 2 â Register the Override
In SuiteCRM 8, custom service overrides must be registered via a Service Provider.
Create the file:
extensions/custom/OutboundEmail/Service/CustomOutboundEmailServiceProvider.php
and add:
<?php
namespace App\Extensions\Custom\OutboundEmail\Service;
use Illuminate\Support\ServiceProvider;
use SuiteCRM\Core\OutboundEmail\Service\OutboundEmailConfigurationService;
class CustomOutboundEmailServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->extend(OutboundEmailConfigurationService::class, function ($service, $app) {
return new CustomOutboundEmailConfigurationService(
$app['SuiteCRM\Core\OutboundEmail\Repository\OutboundEmailConfigurationRepository'],
$app['SuiteCRM\Core\User\UserService'],
$app['SuiteCRM\Core\Service\ConfigurationService']
);
});
}
}
Step 3 â Rebuild Cache
Run (from your SuiteCRM 8 root):
php bin/console cache:clear php bin/console cache:warmup
or through Admin â Repair â Rebuild Backend Cache
HTH