Skip to content
Snippets Groups Projects
Commit b098bc42 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add support (and tests) for SMTP connection time limit. (#1468)

parent 5dc2dc4f
No related merge requests found
...@@ -538,6 +538,11 @@ port = 25 ...@@ -538,6 +538,11 @@ port = 25
; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol ; connection. If no explicit protocol ('tls' or 'ssl') is configured, a protocol
; based on the configured port is chosen (587 -> tls, 487 -> ssl). ; based on the configured port is chosen (587 -> tls, 487 -> ssl).
;secure = tls ;secure = tls
; This setting enforces a limit (in seconds) on the lifetime of an SMTP
; connection, which can be useful when sending batches of emails, since it can
; help avoid errors caused by server timeouts. Comment out the setting to disable
; the limit.
connection_time_limit = 60
; Uncomment this setting to disable outbound mail but simulate success; this ; Uncomment this setting to disable outbound mail but simulate success; this
; is useful for interface testing but should never be used in production! ; is useful for interface testing but should never be used in production!
;testOnly = true ;testOnly = true
......
...@@ -83,6 +83,10 @@ class Factory implements FactoryInterface ...@@ -83,6 +83,10 @@ class Factory implements FactoryInterface
$settings['connection_config']['ssl'] = 'ssl'; $settings['connection_config']['ssl'] = 'ssl';
} }
} }
if (isset($config->Mail->connection_time_limit)) {
$settings['connection_time_limit']
= $config->Mail->connection_time_limit;
}
return new Smtp(new SmtpOptions($settings)); return new Smtp(new SmtpOptions($settings));
} }
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
*/ */
namespace VuFindTest\Mailer; namespace VuFindTest\Mailer;
use VuFind\Mailer\Factory as MailerFactory;
use VuFind\Mailer\Mailer; use VuFind\Mailer\Mailer;
use VuFindTest\Container\MockContainer;
use Zend\Mail\Address; use Zend\Mail\Address;
use Zend\Mail\AddressList; use Zend\Mail\AddressList;
...@@ -42,6 +44,43 @@ use Zend\Mail\AddressList; ...@@ -42,6 +44,43 @@ use Zend\Mail\AddressList;
*/ */
class MailerTest extends \VuFindTest\Unit\TestCase class MailerTest extends \VuFindTest\Unit\TestCase
{ {
/**
* Test that the factory configures the object correctly.
*
* @return void
*/
public function testFactoryConfiguration()
{
$config = new \Zend\Config\Config(
[
'Mail' => [
'host' => 'vufindtest.localhost',
'port' => 123,
'connection_time_limit' => 600,
'name' => 'foo',
'username' => 'vufinduser',
'password' => 'vufindpass',
]
]
);
$cm = new MockContainer($this);
$cm->set('config', $config);
$sm = new MockContainer($this);
$sm->set(\VuFind\Config\PluginManager::class, $cm);
$factory = new MailerFactory();
$mailer = $factory($sm, Mailer::class);
$options = $mailer->getTransport()->getOptions();
$this->assertEquals('vufindtest.localhost', $options->getHost());
$this->assertEquals('foo', $options->getName());
$this->assertEquals(123, $options->getPort());
$this->assertEquals(600, $options->getConnectionTimeLimit());
$this->assertEquals('login', $options->getConnectionClass());
$this->assertEquals(
['username' => 'vufinduser', 'password' => 'vufindpass'],
$options->getConnectionConfig()
);
}
/** /**
* Test sending an email. * Test sending an email.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment