protected void Page_Load(object sender, EventArgs e)
        {
            hMailServerNetRemote.IClassFactory cf = RemoteActivation.GetRemoteClassFactory("http://216.167.175.124/hMailServerWebAdmin/");

            hMailServerNetRemote.IApplication application;
            if (Session["hMailServerNetRemoteApplication"] == null)
            {
                application = cf.CreateApplication();
                Session["hMailServerNetRemoteApplication"] = application;
            }
            else
            {
                application = (hMailServerNetRemote.Application)Session["hMailServerNetRemoteApplication"];
            }

            // the rest is the same
            application.Authenticate("Administrator", "testar");

            // You can do it like VB, but let's do it the C# way. :)
            // hMailServerNetRemote.Domain domain = application.Domains.ItemByName("example.com");
            hMailServerNetRemote.IDomain domain = application.Domains["example.com"];

            hMailServerNetRemote.IAccount account = domain.Accounts.ItemByAddress("*****@*****.**");
            account.Password = "******";
            account.Save();
        }
        private MembershipUser GetUserFromAccount(hMailServerNetRemote.IAccount account)
        {
            string   address                 = account.Address;
            object   providerUserKey         = address;
            string   username                = address;
            string   email                   = address;
            string   passwordQuestion        = "";
            string   comment                 = "";
            bool     isApproved              = true;
            bool     isLockedOut             = false;
            DateTime creationDate            = DateTime.Now;
            DateTime lastLoginDate           = account.LastLogonTime;
            DateTime lastActivityDate        = lastLoginDate;
            DateTime lastPasswordChangedDate = DateTime.Now;
            DateTime lastLockedOutDate       = DateTime.Now;

            MembershipUser u = new MembershipUser(this.Name,
                                                  username,
                                                  providerUserKey,
                                                  email,
                                                  passwordQuestion,
                                                  comment,
                                                  isApproved,
                                                  isLockedOut,
                                                  creationDate,
                                                  lastLoginDate,
                                                  lastActivityDate,
                                                  lastPasswordChangedDate,
                                                  lastLockedOutDate);

            return(u);
        }
        //
        // MembershipProvider.GetUserNameByEmail
        //

        public override string GetUserNameByEmail(string email)
        {
            hMailServerNetRemote.IAccount account = GetAccount(email);
            if (account == null)
            {
                return("");
            }

            return(email);
        }
        //
        // MembershipProvider.GetUser(object, bool)
        //

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            hMailServerNetRemote.IAccount account = GetAccount((string)providerUserKey);
            if (account == null)
            {
                return(null);
            }

            MembershipUser u = GetUserFromAccount(account);

            return(u);
        }
        //
        // MembershipProvider.ResetPassword
        //

        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            if (answer == null && RequiresQuestionAndAnswer)
            {
                UpdateFailureCount(username, "passwordAnswer");

                throw new ProviderException("Password answer required for password reset.");
            }

            string newPassword =
                System.Web.Security.Membership.GeneratePassword(newPasswordLength, MinRequiredNonAlphanumericCharacters);

            ValidatePasswordEventArgs args =
                new ValidatePasswordEventArgs(username, newPassword, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                if (args.FailureInformation != null)
                {
                    throw args.FailureInformation;
                }
                else
                {
                    throw new MembershipPasswordException("Reset password canceled due to password validation failure.");
                }
            }

            hMailServerNetRemote.IAccount account = GetAccount(username);

            if (account == null)
            {
                throw new ProviderException("Can't find user");
            }

            account.Password = newPassword;
            account.Save();

            return(newPassword);
        }
        //
        // MembershipProvider.ValidateUser
        //

        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;


            hMailServerNetRemote.IApplication app     = RemoteActivation.GetRemotehMailServerApplication();
            hMailServerNetRemote.IAccount     account = app.Authenticate(username, password);

            if (account != null)
            {
                isValid = true;
            }
            else
            {
                UpdateFailureCount(username, "password");
            }

            return(isValid);
        }
        //
        // System.Web.Security.MembershipProvider methods.
        //

        //
        // MembershipProvider.ChangePassword
        //

        public override bool ChangePassword(string username, string oldPwd, string newPwd)
        {
            if (!ValidateUser(username, oldPwd))
            {
                return(false);
            }

            ValidatePasswordEventArgs args =
                new ValidatePasswordEventArgs(username, newPwd, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                if (args.FailureInformation != null)
                {
                    throw args.FailureInformation;
                }
                else
                {
                    throw new MembershipPasswordException("Change password canceled due to new password validation failure.");
                }
            }

            string[] sp = username.Split(new Char[] { '@' });

            if (sp.Length != 2)
            {
                return(false);
            }

            hMailServerNetRemote.IApplication app     = RemoteActivation.GetRemotehMailServerApplication();
            hMailServerNetRemote.IDomain      domain  = app.Domains.ItemByName(sp[1]);
            hMailServerNetRemote.IAccount     account = domain.Accounts[username];
            account.Password = newPwd;
            account.Save();

            return(true);
        }
        //
        // GetUserFromReader
        //    A helper function that takes the current row from the MySqlDataReader
        // and hydrates a MembershiUser from the values. Called by the
        // MembershipUser.GetUser implementation.
        //

        private hMailServerNetRemote.IAccount GetAccount(string email)
        {
            hMailServerNetRemote.IApplication app = RemoteActivation.GetRemotehMailServerApplication();
            string[] sp = email.Split(new Char[] { '@' });

            if (sp.Length != 2)
            {
                return(null);
            }

            hMailServerNetRemote.IDomain domain = app.Domains.ItemByName(sp[1]);
            if (domain == null)
            {
                return(null);
            }

            hMailServerNetRemote.IAccount account = domain.Accounts.ItemByAddress(email);
            if (account == null)
            {
                return(null);
            }

            return(account);
        }