public object ConnectAndSaveMailServerInfo(string host, string user, string password) { try { if (string.IsNullOrEmpty(host)) { throw new ArgumentException("host"); } var ipList = new DnsLookup().GetDomainIPs(host).ToList(); if (!ipList.Any()) { throw new Exception("could not get host ip"); } var firstIpItem = ipList.FirstOrDefault(); if (firstIpItem == null) { throw new Exception("could not get host ip"); } var ip = firstIpItem.ToString(); if (!PingHost(ip, 3306)) { throw new Exception(string.Format(Resource.MailServicePingErrorMsg, ip)); } if (string.IsNullOrEmpty(user)) { throw new ArgumentException("user"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("password"); } var connectionString = string.Format(MailServiceHelper.ConnectionStringFormat, ip, MailServiceHelper.DefaultDatabase, user, password); var data = GetAuthData(connectionString, ip); Save(connectionString, ip, data[0], data[1]); return(new { status = "success", message = Resource.MailServiceSaveSuccessMsg }); } catch (Exception exception) { Logger.Error(exception.Message, exception); return(new { status = "error", message = exception.Message.HtmlEncode() }); } }