Different SMTP configurations for multi domains in Typo3 11.5

Is there a way to set up multiple SMTP accounts for sending emails if the Typo installation includes multiple domains?

Ideally, each domain should use its own SMTP account for sending.

In theory, I could adapt the LocalConfiguration.php, but the system tends to overwrite it, so that’s a bad idea.

I would be open to further ideas :slight_smile:

Yes, you could check for different environments in typo3conf/AdditionalConfiguration.php. This example is taken from the automatically generated file from DDEV:

<?php

/**
 * #ddev-generated: Automatically generated TYPO3 AdditionalConfiguration.php file.
 * ddev manages this file and may delete or overwrite the file unless this comment is removed.
 * It is recommended that you leave this file alone.
 */

if (getenv('IS_DDEV_PROJECT') == 'true') {
    $GLOBALS['TYPO3_CONF_VARS'] = array_replace_recursive(
        $GLOBALS['TYPO3_CONF_VARS'],
        [
            // This mail configuration sends all emails to mailhog
            'MAIL' => [
                'transport' => 'smtp',
                'transport_smtp_encrypt' => false,
                'transport_smtp_server' => 'localhost:1025',
            ],
        ]
    );
}

I think that multiple domains are the problem. Not environments :wink:
Never mind, the AdditionalConfiguration is the right place for this I think. I would try such kind of check the Domain and use it in that AdditionalConfiguration file. We did similar stuff to use different single pids for news in old realurl configurations (long time ago).
Use a configuration array for each domain:

$mailConfig = [
  'www.domain1.de' => [
    'transport' => 'smtp',
    'transport_smtp_username' => 'my_userame',
    .....
  ],
  'www.domain2.de' => [
    'transport' => 'smtp',
    'transport_smtp_username' => 'my_other_userame',
    .....
  ],
];

and then use it in the config

$GLOBALS['TYPO3_CONF_VARS']['MAIL']  =>  $mailConfig[$_SERVER['HTTP_HOST'];

or merge that mailConfig array if you don’t want to set all needed values in every configMail array.
Code is not tested, just found it in our old wiki in the very old realurl config stuff but I think it should work.

1 Like

Sorry, I was thinking about ApplicationContext. Are the domains linked to those in the site configuration?

I have been using this construct in AdditionalConfiguration.php;

// settings based on application contexts
$applicationContext = \TYPO3\CMS\Core\Core\Environment::getContext();
switch ($applicationContext) {
    case 'Production/Domain1':
        $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_smtp_username']='username1';
        break;
    case 'Production/Domain2':
        // other settings here
        break;
}

There is also a PSR-14 event to adjust the mailer settings:
https://docs.typo3.org/m/typo3/reference-coreapi/12.4/en-us/ApiOverview/Events/Events/Core/Mail/AfterMailerInitializationEvent.html

Each domain has his own siteconfiguration. The domains are complete differten, also their content and the company.

So. Das hier funktioniert bei mir jetzt. Vielen Dank für die Tipps.

if (($_SERVER[‘SERVER_NAME’] ?? ‘’) === ‘www.domain.de’) {
$GLOBALS[‘TYPO3_CONF_VARS’] = array_replace_recursive(
$GLOBALS[‘TYPO3_CONF_VARS’],
[
// This mail configuration sends all emails to mailhog
‘MAIL’ => [
‘transport’ => ‘smtp’,
‘transport_sendmail_command’ => ‘’,
‘transport_smtp_encrypt’ => true,
‘transport_smtp_password’ => ‘password’,
‘transport_smtp_server’ => ‘smtp.mail.de:465’,
‘transport_smtp_username’ => ‘mail2@mail.de’,
],
]
);
} else {
$GLOBALS[‘TYPO3_CONF_VARS’] = array_replace_recursive(
$GLOBALS[‘TYPO3_CONF_VARS’],
[
// This mail configuration sends all emails to mailhog
‘MAIL’ => [
‘transport’ => ‘smtp’,
‘transport_sendmail_command’ => ‘’,
‘transport_smtp_encrypt’ => true,
‘transport_smtp_password’ => ‘password’,
‘transport_smtp_server’ => ‘smtp.mail.de:465’,
‘transport_smtp_username’ => ‘mail1@mail.de’,
],
]
);
}