docs: def ConfigureEmails(config):
    """Guides the user through email setup."""
    print("\n\n-=GRR Emails=-\n"
          "GRR needs to be able to send emails for various logging and\n"
          "alerting functions. The email domain will be appended to GRR\n"
          "usernames when sending emails to users.\n")
  
    existing_log_domain = grr_config.CONFIG.Get("Logging.domain", default=None)
    existing_al_email = grr_config.CONFIG.Get(
        "Monitoring.alert_email", default=None)
    existing_em_email = grr_config.CONFIG.Get(
        "Monitoring.emergency_access_email", default=None)
    if existing_log_domain and existing_al_email and existing_em_email:
      print("Found existing settings:\n"
            "  Email Domain: %s\n  Alert Email Address: %s\n"
            "  Emergency Access Email Address: %s\n" %
            (existing_log_domain, existing_al_email, existing_em_email))
      if RetryBoolQuestion("Do you want to keep this configuration?", True):
        return
  
    print("\n\n-=Monitoring/Email Domain=-\n"
          "Emails concerning alerts or updates must be sent to this domain.\n")
    domain = RetryQuestion("Email Domain e.g example.com",
                           "^([\\.A-Za-z0-9-]+)*$",
                           grr_config.CONFIG.Get("Logging.domain"))
    config.Set("Logging.domain", domain)
  
    print("\n\n-=Alert Email Address=-\n"
          "Address where monitoring events get sent, e.g. crashed clients, \n"
          "broken server, etc.\n")
    email = RetryQuestion("Alert Email Address", "", "grr-monitoring@%s" % domain)
    config.Set("Monitoring.alert_email", email)
  
    print("\n\n-=Emergency Email Address=-\n"
          "Address where high priority events such as an emergency ACL bypass "
          "are sent.\n")
    emergency_email = RetryQuestion("Emergency Access Email Address", "",
                                    "grr-emergency@%s" % domain)
    config.Set("Monitoring.emergency_access_email", emergency_email)