diff --git a/config/vufind/config.ini b/config/vufind/config.ini
index dd0eebe0be9d9c91534916b4df83714df221edb9..50906ba0f16197086108c4db73611005418abb99 100644
--- a/config/vufind/config.ini
+++ b/config/vufind/config.ini
@@ -407,6 +407,9 @@ 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
+; Uncomment this setting to disable outbound mail but simulate success; this
+; is useful for interface testing but should never be used in production!
+;testOnly = true
 ; If set to false, users can send anonymous emails; otherwise, they must log in first
 require_login   = true
 ; Should we put the logged-in user's address in the "from" field by default?
diff --git a/module/VuFind/src/VuFind/Mailer/Factory.php b/module/VuFind/src/VuFind/Mailer/Factory.php
index 46ca1d9c3966285351dc5432e222cfc9f2dd3cd5..11617a5ed22f8b08c84affc846114051d0f20497 100644
--- a/module/VuFind/src/VuFind/Mailer/Factory.php
+++ b/module/VuFind/src/VuFind/Mailer/Factory.php
@@ -26,6 +26,7 @@
  * @link     http://vufind.org/wiki/vufind2:developer_manual Wiki
  */
 namespace VuFind\Mailer;
+use Zend\Mail\Transport\InMemory;
 use Zend\Mail\Transport\Smtp, Zend\Mail\Transport\SmtpOptions;
 use Zend\ServiceManager\ServiceLocatorInterface;
 
@@ -43,16 +44,18 @@ use Zend\ServiceManager\ServiceLocatorInterface;
 class Factory implements \Zend\ServiceManager\FactoryInterface
 {
     /**
-     * Create service
+     * Build the mail transport object.
      *
-     * @param ServiceLocatorInterface $sm Service manager
+     * @param \Zend\Config\Config $config Configuration
      *
-     * @return mixed
+     * @return InMemory|Smtp
      */
-    public function createService(ServiceLocatorInterface $sm)
+    protected function getTransport($config)
     {
-        // Load configurations:
-        $config = $sm->get('VuFind\Config')->get('config');
+        // In test mode? Return fake object:
+        if (isset($config->Mail->testOnly) && $config->Mail->testOnly) {
+            return new InMemory();
+        }
 
         // Create mail transport:
         $settings = [
@@ -76,10 +79,22 @@ class Factory implements \Zend\ServiceManager\FactoryInterface
                 }
             }
         }
-        $transport = new Smtp();
-        $transport->setOptions(new SmtpOptions($settings));
+        return new Smtp(new SmtpOptions($settings));
+    }
+
+    /**
+     * Create service
+     *
+     * @param ServiceLocatorInterface $sm Service manager
+     *
+     * @return mixed
+     */
+    public function createService(ServiceLocatorInterface $sm)
+    {
+        // Load configurations:
+        $config = $sm->get('VuFind\Config')->get('config');
 
         // Create service:
-        return new \VuFind\Mailer\Mailer($transport);
+        return new \VuFind\Mailer\Mailer($this->getTransport($config));
     }
 }
diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
index 10e5d92f32e902af5f7865ccc54209bc8a2f2a4a..1c48074b786083dfaf1e60af84b1371de601549a 100644
--- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
+++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/RecordActionsTest.php
@@ -242,7 +242,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase
     {
         // Change the theme:
         $this->changeConfigs(
-            ['config' => ['Site' => ['theme' => 'bootstrap3']]]
+            [
+                'config' => [
+                    'Site' => ['theme' => 'bootstrap3'],
+                    'Mail' => ['testOnly' => 1],
+                ]
+            ]
         );
 
         // Go to a record view
@@ -295,7 +300,12 @@ class RecordActionsTest extends \VuFindTest\Unit\MinkTestCase
     {
         // Change the theme:
         $this->changeConfigs(
-            ['config' => ['Site' => ['theme' => 'bootstrap3']]]
+            [
+                'config' => [
+                    'Site' => ['theme' => 'bootstrap3'],
+                    'Mail' => ['testOnly' => 1],
+                ]
+            ]
         );
 
         // Go to a record view