diff --git a/config/vufind/config.ini b/config/vufind/config.ini index 0ca15445a5f..30a28dc0781 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -704,6 +704,14 @@ port = 25 ; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol ; based on the configured port is chosen (587 -> tls, 487 -> ssl). ;secure = tls +; This setting enforces a limit (in seconds) on the lifetime of an SMTP +; connection before the connection is checked, which can be useful when sending +; batches of emails, since it can help avoid errors caused by server timeouts. +; This is mapped to the ping_threshold option in Symfony Mailer. +; Comment out the setting to use the default ping threshold. +; See https://symfony.com/doc/current/mailer.html#other-options for more +; information. +connection_time_limit = 60 ; The server name to report to the upstream mail server when sending mail. ;name = vufind.myuniversity.edu diff --git a/module/VuFind/src/VuFind/Mailer/Factory.php b/module/VuFind/src/VuFind/Mailer/Factory.php index e608e12e3e2..43a393f17d1 100644 --- a/module/VuFind/src/VuFind/Mailer/Factory.php +++ b/module/VuFind/src/VuFind/Mailer/Factory.php @@ -85,8 +85,16 @@ protected function getDSN(array $config): string if ($port = $config['Mail']['port'] ?? null) { $dsn .= ":$port"; } + + $dsnParams = []; if ($name = $config['Mail']['name'] ?? null) { - $dsn .= "?local_domain=$name"; + $dsnParams['local_domain'] = $name; + } + if (null !== ($limit = $config['Mail']['connection_time_limit'] ?? null)) { + $dsnParams['ping_threshold'] = $limit; + } + if ($dsnParams) { + $dsn .= '?' . http_build_query($dsnParams); } return $dsn; diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php index bcd9510822d..b1b9bef9fe8 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Mailer/MailerTest.php @@ -62,9 +62,10 @@ public function testFactoryConfiguration() 'Mail' => [ 'host' => 'vufindtest.localhost', 'port' => 123, - 'name' => 'foo', + 'name' => 'foo?bar', 'username' => 'vufinduser', 'password' => 'vufindpass', + 'connection_time_limit' => 60, ], ]; $configDsn = [ @@ -78,7 +79,7 @@ public function testFactoryConfiguration() $factory = new MailerFactory(); $this->assertEquals( - 'smtp://vufinduser:vufindpass@vufindtest.localhost:123?local_domain=foo', + 'smtp://vufinduser:vufindpass@vufindtest.localhost:123?local_domain=foo%3Fbar&ping_threshold=60', $this->callMethod($factory, 'getDSN', [$config]) );