How to use multiple SMTP accounts in one TYPO3 installation
When TYPO3 is used to serve multiple websites in one installation, it may sometimes be required to configure multiple SMTP accounts in order to send emails from TYPO3 (e.g. mailforms or notifications) to different recipients. This may especially be important, when the recipient mailserver has a strict spam filter or when the domain uses a SPF, DKIM or DMARC and the mailserver only accepts emails from thrusted sources.
In TYPO3 you can configure one global SMTP server in LocalConfiguration.php by using the following settings:
This setting however reflects to any hosted website in your TYPO3 installation and the email-server for typo3-website1.tld may possible not accept emails with a sender from the domain typo3-website2.tld.
In order to provide multiple SMTP servers for different websites in a TYPO3 installation, I configure different SMTP servers in AdditionalConfiguration.php
Since AdditionalConfiguration.php is evaluated on every request, TYPO3 will conditionally use the email settings
depending on the $_SERVER['SERVER_NAME'] variable.
Note, that this solution only applies to web requests and does not work in CLI context (e.g. scheduler task).