diff --git a/typo3/sysext/core/Classes/Mail/TransportFactory.php b/typo3/sysext/core/Classes/Mail/TransportFactory.php index 2677dbbc4c1beb7c3ea504476b654088c24a6d84..81b2a449fa564fc575b6c9934ea0e035e0914cec 100644 --- a/typo3/sysext/core/Classes/Mail/TransportFactory.php +++ b/typo3/sysext/core/Classes/Mail/TransportFactory.php @@ -112,6 +112,11 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface $this->dispatcher, $this->logManager->getLogger(EsmtpTransport::class) ); + $streamOptions = (array)($mailSettings['transport_smtp_stream_options'] ?? []); + if (!empty($streamOptions)) { + $stream = $transport->getStream(); + $stream->setStreamOptions(array_merge_recursive($stream->getStreamOptions(), $streamOptions)); + } // Need authentication? $username = (string)($mailSettings['transport_smtp_username'] ?? ''); if ($username !== '') { @@ -125,6 +130,19 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface if ($mailDomain !== '') { $transport->setLocalDomain($mailDomain); } + $restartThreshold = (int)($mailSettings['transport_smtp_restart_threshold'] ?? 0); + $restartThresholdSleep = (int)($mailSettings['transport_smtp_restart_threshold_sleep'] ?? 0); + if ($restartThreshold > 0) { + if ($restartThresholdSleep < 0) { + // invalid, use default for threshold sleep + $restartThresholdSleep = 0; + } + $transport->setRestartThreshold($restartThreshold, $restartThresholdSleep); + } + $pingThreshold = (int)($mailSettings['transport_smtp_ping_threshold'] ?? 0); + if ($pingThreshold > 0) { + $transport->setPingThreshold($pingThreshold); + } break; case 'sendmail': $sendmailCommand = $mailSettings['transport_sendmail_command'] ?? @ini_get('sendmail_path'); @@ -181,6 +199,7 @@ class TransportFactory implements SingletonInterface, LoggerAwareInterface but must implement that interface to be used as a mail transport.', 1323006478); } } + return $transport; } diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php index 0b3a455b03e265710e9fa6114c71b3c644fad20d..281931e5fab42d4c7317e804f622d174ec49b324 100644 --- a/typo3/sysext/core/Configuration/DefaultConfiguration.php +++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php @@ -1470,6 +1470,10 @@ return [ 'transport_smtp_username' => '', 'transport_smtp_password' => '', 'transport_smtp_domain' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => null, 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'transport_spool_type' => '', diff --git a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml index a020d1fbe7f1b13966a4728dd6f8e1dac1aca662..b7f319c12f32b6dd3d5135d3eabbc3c99f273b11 100644 --- a/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml +++ b/typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml @@ -607,6 +607,20 @@ MAIL: transport_smtp_domain: type: text description: '<em>only with transport=smtp</em>: Mail domain under which emails will be sent.' + transport_smtp_restart_threshold: + type: text + description: '<em>only with transport=smtp</em>: Sets the maximum number of messages to send before re-starting the transport.' + transport_smtp_restart_threshold_sleep: + type: text + description: '<em>only with transport=smtp</em>: The number of seconds to sleep between stopping and re-starting the transport.' + transport_smtp_ping_threshold: + type: text + description: '<em>only with transport=smtp</em>: Sets the minimum number of seconds required between two messages, before the server is pinged.' + transport_smtp_stream_options: + type: mixed + description: | + <em>only with transport=smtp</em>: Sets the stream context options for the smtp stream<br /> + The configuration with an array must be made in the <code>AdditionalConfiguration.php</code>; see <a href="https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/GlobalValues/Typo3ConfVars/Index.html#file-additionalconfiguration-php" target="_blank" rel="noreferrer">the documentation</a> for details.<br /> transport_sendmail_command: type: text description: '<em>only with transport=sendmail</em>: The command to call to send a mail locally.' diff --git a/typo3/sysext/core/Documentation/Changelog/12.0/Feature-94544-AddNewSMTPConfigurationSettings.rst b/typo3/sysext/core/Documentation/Changelog/12.0/Feature-94544-AddNewSMTPConfigurationSettings.rst new file mode 100644 index 0000000000000000000000000000000000000000..75c455a462cc96d3108293aecc58815f2343448c --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/12.0/Feature-94544-AddNewSMTPConfigurationSettings.rst @@ -0,0 +1,56 @@ +.. include:: ../../Includes.txt + +===================================================== +Feature: #94544 - Add new SMTP configuration settings +===================================================== + +See :issue:`94544` + +Description +=========== + +A few more SMTP options are now supported by TYPO3 and can be set in the Install Tool: + +- transport_smtp_restart_threshold +Sets the maximum number of messages to send before re-starting the transport. + +- transport_smtp_restart_threshold_sleep +The number of seconds to sleep between stopping and re-starting the transport + +- transport_smtp_ping_threshold +Sets the minimum number of seconds required between two messages, before the server is pinged. If +the transport wants to send a message and the time since the last message exceeds the specified +threshold, the transport will ping the server first (NOOP command) to check if the connection is +still alive. Otherwise the message will be sent without pinging the server first. + +Do not set the threshold too low, as the SMTP server may drop the connection if there are too many +non-mail commands (like pinging the server with NOOP). + +It is now also possible to define an array with SMTP stream options in the AdditionalConfiguration.php. + +Configuration Example: + +.. code-block:: php + return [ + //.... + 'MAIL' => [ + 'transport' => 'smtp', + 'transport_sendmail_command' => ' -t -i ', + 'transport_smtp_server' => 'localhost:1025', + 'transport_smtp_stream_options' => [ + 'ssl' => [ + 'verify_peer' => false, + 'verify_peer_name' => false, + ] + ], + ], + //.... + ]; + + +Impact +====== + +Now it is possible to set more options for some smtp cases. + +.. index:: LocalConfiguration, ext:core diff --git a/typo3/sysext/core/Tests/Unit/Mail/TransportFactoryTest.php b/typo3/sysext/core/Tests/Unit/Mail/TransportFactoryTest.php index ccb3ab8f469ba03213953ca62b2a57149cbdc6b0..4d14539f9d950d471a95ae327a9365a46792f76c 100644 --- a/typo3/sysext/core/Tests/Unit/Mail/TransportFactoryTest.php +++ b/typo3/sysext/core/Tests/Unit/Mail/TransportFactoryTest.php @@ -78,6 +78,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -108,6 +112,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -135,6 +143,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -163,6 +175,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -225,6 +241,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -248,6 +268,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -281,6 +305,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_sendmail_command' => '', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', @@ -314,6 +342,10 @@ class TransportFactoryTest extends UnitTestCase 'transport_smtp_username' => '', 'transport_smtp_password' => '', 'transport_sendmail_command' => '', + 'transport_smtp_restart_threshold' => '', + 'transport_smtp_restart_threshold_sleep' => '', + 'transport_smtp_ping_threshold' => '', + 'transport_smtp_stream_options' => [], 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', 'defaultMailFromName' => '',