diff --git a/core/lib/Drupal/Core/Mail/VariableLog.php b/core/lib/Drupal/Core/Mail/VariableLog.php
index 3dfe5b6..cb0c256 100644
--- a/core/lib/Drupal/Core/Mail/VariableLog.php
+++ b/core/lib/Drupal/Core/Mail/VariableLog.php
@@ -21,9 +21,9 @@ class VariableLog extends PhpMail implements MailInterface {
    * Accepts an e-mail message and store it in a variable.
    */
   public function mail(array $message) {
-    $captured_emails = variable_get('drupal_test_email_collector', array());
+    $captured_emails = state()->get('drupal_test_email_collector') ?: array();
     $captured_emails[] = $message;
-    variable_set('drupal_test_email_collector', $captured_emails);
+    state()->set('drupal_test_email_collector', $captured_emails);
 
     return TRUE;
   }
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 9d151e0..8cec5d8 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -963,8 +963,8 @@ protected function tearDown() {
     // In case a fatal error occurred that was not in the test process read the
     // log to pick up any fatal errors.
     simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
-
-    $emailCount = count(variable_get('drupal_test_email_collector', array()));
+    $captured_emails = state()->get('drupal_test_email_collector') ?: array();
+    $emailCount = count($captured_emails);
     if ($emailCount) {
       $message = format_plural($emailCount, '1 e-mail was sent during this test.', '@count e-mails were sent during this test.');
       $this->pass($message, t('E-mail'));
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index ecf2861..9165673 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -2000,7 +2000,7 @@ protected function drupalGetSettings() {
    *   An array containing e-mail messages captured during the current test.
    */
   protected function drupalGetMails($filter = array()) {
-    $captured_emails = variable_get('drupal_test_email_collector', array());
+    $captured_emails = state()->get('drupal_test_email_collector') ?: array();
     $filtered_emails = array();
 
     foreach ($captured_emails as $message) {
@@ -2923,7 +2923,7 @@ protected function assertNoResponse($code, $message = '') {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertMail($name, $value = '', $message = '') {
-    $captured_emails = variable_get('drupal_test_email_collector', array());
+    $captured_emails = state()->get('drupal_test_email_collector') ?: array();
     $email = end($captured_emails);
     return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, t('E-mail'));
   }
