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
parent
a8729aad07
commit
7c5a6c11f9
|
@ -226,7 +226,15 @@ class MailManager extends DefaultPluginManager implements MailManagerInterface {
|
|||
*/
|
||||
public function doMail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE) {
|
||||
$site_config = $this->configFactory->get('system.site');
|
||||
$site_mail = $site_config->get('mail');
|
||||
// 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.
|
||||
if (empty($site_mail)) {
|
||||
$site_mail = ini_get('sendmail_from');
|
||||
}
|
||||
|
|
|
@ -188,45 +188,88 @@ class UserAdminTest extends BrowserTestBase {
|
|||
$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 = $this->randomMachineName() . '@example.com';
|
||||
$notify_address = $this->randomMachineName() . '@example.com';
|
||||
$server_address = 'site.admin@example.com';
|
||||
$notify_address = 'site.notify@example.com';
|
||||
$system
|
||||
->set('mail', $server_address)
|
||||
->set('mail_notification', $notify_address)
|
||||
->save();
|
||||
|
||||
// Register a new user account.
|
||||
$edit = [];
|
||||
$edit['name'] = $this->randomMachineName();
|
||||
$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 ' . $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' => $server_address,
|
||||
'from' => $notify_address,
|
||||
'subject' => $subject,
|
||||
]);
|
||||
$this->assertCount(1, $admin_mail, 'New user mail to admin is sent to configured Notification Email address');
|
||||
$this->assertCount(1, $admin_mail);
|
||||
|
||||
// Ensure that user notification mail is sent from the configured
|
||||
// Notification Email address.
|
||||
$user_mail = $this->drupalGetMails([
|
||||
'to' => $edit['mail'],
|
||||
'from' => $server_address,
|
||||
'from' => $notify_address,
|
||||
'reply-to' => $notify_address,
|
||||
'subject' => $subject,
|
||||
]);
|
||||
$this->assertCount(1, $user_mail, 'New user mail to user is sent from configured Notification Email address');
|
||||
$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,
|
||||
'subject' => $subject,
|
||||
]);
|
||||
$this->assertCount(1, $user_mail);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue