From b4a1e808a4ef64d2d2daf3dfb6c9f15687aa4201 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Tue, 10 Jan 2023 15:00:03 -0600
Subject: [PATCH] Revert "Issue #3201472 by anup.sinha, _utsavsharma,
 smustgrave, Ralf Eisler, Christian DeLoach, xjm: Notification email address
 does not override the default system email address for account notifications"

This reverts commit 7c5a6c11f967d107b54b39cdd1a1770fde12f616.
---
 core/lib/Drupal/Core/Mail/MailManager.php     | 10 +---
 .../tests/src/Functional/UserAdminTest.php    | 59 +++----------------
 2 files changed, 9 insertions(+), 60 deletions(-)

diff --git a/core/lib/Drupal/Core/Mail/MailManager.php b/core/lib/Drupal/Core/Mail/MailManager.php
index 39ae0ebf1dc1..df6eb226d072 100644
--- a/core/lib/Drupal/Core/Mail/MailManager.php
+++ b/core/lib/Drupal/Core/Mail/MailManager.php
@@ -226,15 +226,7 @@ public function mail($module, $key, $to, $langcode, $params = [], $reply = NULL,
    */
   public function doMail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE) {
     $site_config = $this->configFactory->get('system.site');
-    // If a custom notification email address has been configured, use that
-    // address.
-    $site_mail = $site_config->get('mail_notification');
-    // Otherwise, use the default site email address.
-    if (empty($site_mail)) {
-      $site_mail = $site_config->get('mail');
-    }
-    // Finally, default to the server email address if no site email has been
-    // configured.
+    $site_mail = $site_config->get('mail');
     if (empty($site_mail)) {
       $site_mail = ini_get('sendmail_from');
     }
diff --git a/core/modules/user/tests/src/Functional/UserAdminTest.php b/core/modules/user/tests/src/Functional/UserAdminTest.php
index 0ff5fd9e0438..32f9673b7247 100644
--- a/core/modules/user/tests/src/Functional/UserAdminTest.php
+++ b/core/modules/user/tests/src/Functional/UserAdminTest.php
@@ -188,88 +188,45 @@ public function testNotificationEmailAddress() {
     $this->assertSession()->responseContains('id="edit-mail-notification-address"');
     $this->drupalLogout();
 
+    // Test custom user registration approval email address(es).
     $config = $this->config('user.settings');
-
     // Allow users to register with admin approval.
     $config
       ->set('verify_mail', TRUE)
       ->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
       ->save();
-
     // Set the site and notification email addresses.
     $system = $this->config('system.site');
-    $server_address = 'site.admin@example.com';
-    $notify_address = 'site.notify@example.com';
+    $server_address = $this->randomMachineName() . '@example.com';
+    $notify_address = $this->randomMachineName() . '@example.com';
     $system
       ->set('mail', $server_address)
       ->set('mail_notification', $notify_address)
       ->save();
-
     // Register a new user account.
     $edit = [];
-    $edit['name'] = 'drupalUser';
+    $edit['name'] = $this->randomMachineName();
     $edit['mail'] = $edit['name'] . '@example.com';
     $this->drupalGet('user/register');
     $this->submitForm($edit, 'Create new account');
     $subject = 'Account details for ' . $edit['name'] . ' at ' . $system->get('name') . ' (pending admin approval)';
-
     // Ensure that admin notification mail is sent to the configured
     // Notification Email address.
     $admin_mail = $this->drupalGetMails([
       'to' => $notify_address,
-      'from' => $notify_address,
+      'from' => $server_address,
       'subject' => $subject,
     ]);
-    $this->assertCount(1, $admin_mail);
-
+    $this->assertCount(1, $admin_mail, 'New user mail to admin is sent to configured Notification Email address');
     // Ensure that user notification mail is sent from the configured
     // Notification Email address.
-    $user_mail = $this->drupalGetMails([
-      'to' => $edit['mail'],
-      'from' => $notify_address,
-      'reply-to' => $notify_address,
-      'subject' => $subject,
-    ]);
-    $this->assertCount(1, $user_mail);
-  }
-
-  /**
-   * Tests email notifications with no custom notification address configured.
-   */
-  public function testNotificationEmailAddressNotSet() {
-    $config = $this->config('user.settings');
-
-    // Allow users to register with admin approval.
-    $config
-      ->set('verify_mail', TRUE)
-      ->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)
-      ->save();
-
-    // Set the site and notification email addresses.
-    $site_configuration = $this->config('system.site');
-    $server_address = 'site.admin@example.com';
-    $site_configuration
-      ->set('mail', $server_address)
-      ->save();
-
-    // Register a new user account.
-    $edit = [];
-    $edit['name'] = 'drupalUser';
-    $edit['mail'] = $edit['name'] . '@example.com';
-    $this->drupalGet('user/register');
-    $this->submitForm($edit, 'Create new account');
-    $subject = 'Account details for ' . $edit['name'] . ' at ' . $site_configuration->get('name') . ' (pending admin approval)';
-
-    // When no custom notification email address is set, the email will be
-    // sent from the site default email address.
     $user_mail = $this->drupalGetMails([
       'to' => $edit['mail'],
       'from' => $server_address,
-      'reply-to' => $server_address,
+      'reply-to' => $notify_address,
       'subject' => $subject,
     ]);
-    $this->assertCount(1, $user_mail);
-
+    $this->assertCount(1, $user_mail, 'New user mail to user is sent from configured Notification Email address');
   }
 
 }
-- 
GitLab