Change system mail on run time when sending mail I have 4 domains using domain access module like a.com, b.com, c.com, d.com. currently when user registers he receives a mail from admin@a.com which is default in site configuration. Now what I want is to Change system mail on run time with respect to 4 diffrent domains so that when user registers from b.com he will receive mail from admin@b.com and so on.As this info is saved in system configuration so how to change the mail id of the site when sending mail on run time.
You can alter the mail using hook_mail_alter(&amp;$message)


  Alter an email message created with MailManagerInterface->mail().


with in message array you have 'from' field as well.

Example

function mymodule_mail_alter(&amp;$message) {
  if ($message['id'] == 'modulename_messagekey') {
    // Login to get domain specific email id.
    $email_id == _some_logic_to_get_email();
    $message['from'] = $email_id;
  }
}


Refernce: https://api.drupal.org/api/drupal/core%21core.api.php/function/hook_mail_alter/8.2.x