diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m
index 50d1fba..9762cb6 100644
--- a/UI/MainUI/SOGoRootPage.m
+++ b/UI/MainUI/SOGoRootPage.m
@@ -200,8 +200,55 @@
   language = [request formValueForKey: @"language"];
   rememberLogin = [[request formValueForKey: @"rememberLogin"] boolValue];
   domain = [request formValueForKey: @"domain"];
+
+  sd = [SOGoSystemDefaults sharedSystemDefaults];
+
+  //multi-domain mode?
+  BOOL multidomainLoginError = false;
+  if ([sd enableDomainBasedUID])
+  {
+    NSArray *userparts;
+    userparts = [username componentsSeparatedByString: @"@"];
+    multidomainLoginError = true;
+
+    //domain setting from webinterface?
+    if ([domain isNotNull])
+    {
+	//the user is not allowed to provide a domain, or only the domain selected 
+	//I added the second option, because typing the full email has become an automatism, which should not cause an error on login!
+	if ( [userparts count]==1 || ( [userparts count]==2 && [[userparts objectAtIndex: 1] isEqualToString: [[SOGoDomainDefaults defaultsForDomain: domain] mailDomain]] ) )
+	{
+	    username = [userparts objectAtIndex: 0];
+	    multidomainLoginError = false;
+	}
+    }
+    else
+    {
+	//the user MUST provide a VALID domain
+	if ([userparts count]==2)
+	{
+	    NSInteger i;
+	    NSString *domainId;
+	    NSString *domainName;
+	    for (i=0;i<[[sd domainIds] count];i++)
+	    {
+		domainId = [[sd domainIds] objectAtIndex: i];
+		domainName = [[SOGoDomainDefaults defaultsForDomain: domainId] mailDomain];
+		if ([domainName isEqualToString: [userparts objectAtIndex: 1]])
+		{
+		    //found matching mailDomain at domainID
+		    multidomainLoginError = false;
+		    username = [userparts objectAtIndex: 0];
+		    domain = domainId;
+		    break;
+		}
+	    }
+	}
+    }
+  }
+
   
-  if ((b = [auth checkLogin: username password: password domain: &domain
+  if (!multidomainLoginError && (b = [auth checkLogin: username password: password domain: &domain
 		 perr: &err expire: &expire grace: &grace])
       && (err == PolicyNoError)  
       // no password policy
@@ -221,7 +268,6 @@
       
       if ([domain isNotNull])
         {
-          sd = [SOGoSystemDefaults sharedSystemDefaults];
           if ([sd enableDomainBasedUID])
             username = [NSString stringWithFormat: @"%@@%@", username, domain];
         }
@@ -231,8 +277,7 @@
                                   inContext: context];
       [response addCookie: authCookie];
 
-      supportedLanguages = [[SOGoSystemDefaults sharedSystemDefaults]
-                             supportedLanguages];
+      supportedLanguages = [sd supportedLanguages];
       loggedInUser = [SOGoUser userWithLogin: username];
       [context setActiveUser: loggedInUser];
       if (language && [supportedLanguages containsObject: language])
@@ -497,6 +542,15 @@
   return item;
 }
 
+- (id) displayitem
+{
+  if ([[SOGoSystemDefaults sharedSystemDefaults] displayMailDomainsInLoginDropDown])
+      return [[SOGoDomainDefaults defaultsForDomain: item] mailDomain];
+  else
+     return item;
+}
+
+
 - (NSArray *) languages
 {
   return [[SOGoSystemDefaults sharedSystemDefaults] supportedLanguages];
diff --git a/UI/Templates/MainUI/SOGoRootPage.wox b/UI/Templates/MainUI/SOGoRootPage.wox
index 85a4e1e..60fd42d 100644
--- a/UI/Templates/MainUI/SOGoRootPage.wox
+++ b/UI/Templates/MainUI/SOGoRootPage.wox
@@ -57,7 +57,7 @@
 		       item="item"
 		       var:selection="item"
 		       var:value="item"
-		       string="item"
+		       string="displayitem"
 		       /></label>
             </var:if>
 	    <label><input id="rememberLogin" type="checkbox" class="checkBox" var:checked="rememberLogin"/> <var:string label:value="Remember username"/></label>
