示例#1
0
		public override void CreateAccount(MailAccount mailbox)
		{
			try
			{
				svcUserAdmin users = new svcUserAdmin();
				PrepareProxy(users);

				GenericResult1 result = users.AddUser(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.Password,
					GetDomainName(mailbox.Name),
					mailbox.FirstName,
					mailbox.LastName,
					false //domain admin is false
					);

				if (!result.Result)
					throw new Exception(result.Message);

				// set forwarding settings
				result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
					mailbox.Name, mailbox.DeleteOnForward,
					(mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));

				if (!result.Result)
					throw new Exception(result.Message);

				// set additional settings
				result = users.SetRequestedUserSettings(AdminUsername, AdminPassword,
					mailbox.Name,
					new string[]
                    {
                        "isenabled=" + mailbox.Enabled.ToString(),
                        "maxsize=" + mailbox.MaxMailboxSize.ToString(),
                        "passwordlocked=" + mailbox.PasswordLocked.ToString(),
                        "replytoaddress=" + (mailbox.ReplyTo != null ? mailbox.ReplyTo : ""),
                        "signature=" + (mailbox.Signature != null ? mailbox.Signature : ""),
						"spamforwardoption=none"
                    });

				if (!result.Result)
					throw new Exception(result.Message);

				// set autoresponder settings
				result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.ResponderEnabled,
					(mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""),
					(mailbox.ResponderMessage != null ? mailbox.ResponderMessage : ""));

				if (!result.Result)
					throw new Exception(result.Message);

			}
			catch (Exception ex)
			{
				throw new Exception("Could not create mailbox", ex);
			}
		}
示例#2
0
        public virtual void UpdateAccount(MailAccount mailbox)
        {
            try
            {
                //get original account
                MailAccount account = GetAccount(mailbox.Name);

                svcUserAdmin users = new svcUserAdmin();
                PrepareProxy(users);

                GenericResult1 result = users.UpdateUser(AdminUsername, AdminPassword,
                    mailbox.Name,
                    mailbox.Password,
                    mailbox.FirstName,
                    mailbox.LastName,
                    account.IsDomainAdmin
                    );

                if (!result.Result)
                    throw new Exception(result.Message);

                // set additional settings
                result = users.SetRequestedUserSettings(AdminUsername, AdminPassword,
                    mailbox.Name,
                    new string[]
                    {
                        "isenabled=" + mailbox.Enabled,
                        "maxsize=" + (mailbox.MaxMailboxSize),
                        "passwordlocked=" + mailbox.PasswordLocked,
                        "replytoaddress=" + (mailbox.ReplyTo ?? ""),
                        "signature=" + (mailbox.Signature ?? "")
                    });

                if (!result.Result)
                    throw new Exception(result.Message);

                // set forwarding settings
                result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
                    mailbox.Name, mailbox.DeleteOnForward,
                    (mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));

                if (!result.Result)
                    throw new Exception(result.Message);

                // set autoresponder settings
                result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword,
                    mailbox.Name,
                    mailbox.ResponderEnabled,
                    (mailbox.ResponderSubject ?? ""),
                    (mailbox.ResponderMessage ?? ""));

                if (!result.Result)
                    throw new Exception(result.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not update mailbox", ex);
            }
        }
示例#3
0
        public virtual MailAccount GetAccount(string mailboxName)
        {
            try
            {
                svcUserAdmin users = new svcUserAdmin();
                PrepareProxy(users);

                UserInfoResult result = users.GetUser(AdminUsername, AdminPassword, mailboxName);

                if (!result.Result)
                    throw new Exception(result.Message);

                MailAccount mailbox = new MailAccount();
                mailbox.Name = result.UserInfo.UserName;
                mailbox.Password = result.UserInfo.Password;
                mailbox.FirstName = result.UserInfo.FirstName;
                mailbox.LastName = result.UserInfo.LastName;
                mailbox.IsDomainAdmin = result.UserInfo.IsDomainAdmin;

                // get additional settings
                string[] requestedSettings = new string[]
                {
                    "isenabled",
                    "maxsize",
                    "passwordlocked",
                    "replytoaddress",
                    "signature"
                };

                SettingsRequestResult addResult = users.GetRequestedUserSettings(AdminUsername, AdminPassword,
                    mailboxName, requestedSettings);

                if (!addResult.Result)
                    throw new Exception(addResult.Message);

                foreach (string pair in addResult.settingValues)
                {
                    string[] parts = pair.Split('=');
                    if (parts[0] == "isenabled") mailbox.Enabled = Boolean.Parse(parts[1]);
                    else if (parts[0] == "maxsize") mailbox.MaxMailboxSize = Int32.Parse(parts[1]);
                    else if (parts[0] == "passwordlocked") mailbox.PasswordLocked = Boolean.Parse(parts[1]);
                    else if (parts[0] == "replytoaddress") mailbox.ReplyTo = parts[1];
                    else if (parts[0] == "signature") mailbox.Signature = parts[1];
                }

                // get forwardings info
                UserForwardingInfoResult forwResult = users.GetUserForwardingInfo(AdminUsername, AdminPassword, mailboxName);

                if (!forwResult.Result)
                    throw new Exception(forwResult.Message);

                string[] forwAddresses = forwResult.ForwardingAddress.Split(';', ',');
                List<string> listForAddresses = new List<string>();
                foreach (string forwAddress in forwAddresses)
                {
                    if (!String.IsNullOrEmpty(forwAddress.Trim()))
                        listForAddresses.Add(forwAddress.Trim());
                }

                mailbox.ForwardingAddresses = listForAddresses.ToArray();
                mailbox.DeleteOnForward = forwResult.DeleteOnForward;

                // get autoresponder info
                UserAutoResponseResult respResult = users.GetUserAutoResponseInfo(AdminUsername, AdminPassword, mailboxName);

                if (!respResult.Result)
                    throw new Exception(respResult.Message);

                mailbox.ResponderEnabled = respResult.Enabled;
                mailbox.ResponderSubject = respResult.Subject;
                mailbox.ResponderMessage = respResult.Body;

                return mailbox;
            }
            catch (Exception ex)
            {
                throw new Exception("Could not get mailbox", ex);
            }
        }
示例#4
0
        /// <summary>
        /// Returns all users that belong to the specified domain
        /// </summary>
        /// <param name="domainName">Domain name</param>
        /// <returns>Array with user names</returns>
        public virtual MailAccount[] GetAccounts(string domainName)
        {
            try
            {
                svcUserAdmin users = new svcUserAdmin();
                PrepareProxy(users);

                UserInfoListResult result = users.GetUsers(AdminUsername, AdminPassword, domainName);

                if (!result.Result)
                    throw new Exception(result.Message);

				List<MailAccount> accounts = new List<MailAccount>();
                
                
                foreach (UserInfo user in result.Users)
                {
                    if (user.IsDomainAdmin && !ImportDomainAdmin)
                        continue;
                                        
                    MailAccount account = new MailAccount();
					account.Name = user.UserName;
					account.Password = user.Password;
					accounts.Add(account);
                }
				return accounts.ToArray();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not get the list of domain mailboxes", ex);
            }
        }
示例#5
0
        public virtual bool AccountExists(string mailboxName)
        {
            try
            {
                svcUserAdmin users = new svcUserAdmin();
                PrepareProxy(users);

                UserInfoResult result = users.GetUser(AdminUsername, AdminPassword, mailboxName);

                return result.Result;
            }
            catch (Exception ex)
            {
                throw new Exception("Could not check whether mailbox exists", ex);
            }
        }
示例#6
0
        public virtual void DeleteAccount(string mailboxName)
        {
            try
            {
                svcUserAdmin users = new svcUserAdmin();
                PrepareProxy(users);

                GenericResult1 result = users.DeleteUser(AdminUsername, AdminPassword,
                    mailboxName, GetDomainName(mailboxName));

                if (!result.Result)
                    throw new Exception(result.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("Could not delete mailbox", ex);
            }
        }
示例#7
0
		public override ServiceProviderItemDiskSpace[] GetServiceItemsDiskSpace(ServiceProviderItem[] items)
		{
			List<ServiceProviderItemDiskSpace> itemsDiskspace = new List<ServiceProviderItemDiskSpace>();

			// update items with diskspace
			foreach (ServiceProviderItem item in items)
			{
				if (item is MailAccount)
				{
					try
					{
                        svcUserAdmin users = new svcUserAdmin();
                        PrepareProxy(users);

                        StatInfoResult userStats = users.GetUserStats(AdminUsername, AdminPassword, item.Name, DateTime.Now, DateTime.Now);
                        if (!userStats.Result)
                        {
                            throw new Exception(userStats.Message);
                        }

                        Log.WriteStart(String.Format("Calculating mail account '{0}' size", item.Name));
                        // calculate disk space
                        ServiceProviderItemDiskSpace diskspace = new ServiceProviderItemDiskSpace();
                        diskspace.ItemId = item.Id;
                        //diskspace.DiskSpace = 0;
                        diskspace.DiskSpace = userStats.BytesSize;
                        itemsDiskspace.Add(diskspace);
                        Log.WriteEnd(String.Format("Calculating mail account '{0}' size", item.Name));
					}
					catch (Exception ex)
					{
						Log.WriteError(ex);
					}
				}
			}
			return itemsDiskspace.ToArray();
		}
示例#8
0
		public void UpdateAccount(MailAccount mailbox)
		{

			try
			{
				//get original account
				MailAccount account = GetAccount(mailbox.Name);

				svcUserAdmin users = new svcUserAdmin();
				PrepareProxy(users);

				string strPassword = mailbox.Password;

				//Don't change password. Get it from mail server.
				if (!mailbox.ChangePassword)
				{
					strPassword = account.Password;
				}

				GenericResult result = users.UpdateUser(
					AdminUsername, AdminPassword, mailbox.Name, strPassword, mailbox.FirstName, mailbox.LastName, mailbox.IsDomainAdmin);

			    if (!result.Result)
			    {
			        if (result.ResultCode == -21)
                        throw new Exception("Password doesn't meet complexity", new Exception(result.Message));
			        
                    throw new Exception(result.Message);
			    }

			    // set forwarding settings
				result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
					mailbox.Name, mailbox.DeleteOnForward,
					(mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));

				if (!result.Result)
					throw new Exception(result.Message);

				// Set additional settings
				result = users.SetRequestedUserSettings(AdminUsername, AdminPassword, mailbox.Name, mailbox.PrepareSetRequestedUserSettingsWebMethodParams());

				if (!result.Result)
					throw new Exception(result.Message);

				// set autoresponder settings
				result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.ResponderEnabled,
					(mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""),
					(mailbox.ResponderMessage != null ? mailbox.ResponderMessage : ""));

				if (!result.Result)
					throw new Exception(result.Message);
			}
			catch (Exception ex)
			{
				throw new Exception("Could not update mailbox", ex);
			}

		}
示例#9
0
		public void CreateAccount(MailAccount mailbox)
		{
			try
			{
				svcUserAdmin users = new svcUserAdmin();
				PrepareProxy(users);

				GenericResult result = users.AddUser(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.Password,
					GetDomainName(mailbox.Name),
					mailbox.FirstName,
					mailbox.LastName,
					mailbox.IsDomainAdmin // domain admin is false
					);

                if (!result.Result)
                {
                    if (result.ResultCode == -21)
                        throw new Exception("Password doesn't meet complexity", new Exception(result.Message));

                    throw new Exception(result.Message);
                }

				// set forwarding settings
				result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
					mailbox.Name, mailbox.DeleteOnForward,
					(mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));

				if (!result.Result)
					throw new Exception(result.Message);

				// set additional settings
				result = users.SetRequestedUserSettings(AdminUsername, AdminPassword, mailbox.Name, mailbox.PrepareSetRequestedUserSettingsWebMethodParams());

				if (!result.Result)
					throw new Exception(result.Message);

				// set autoresponder settings
				result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.ResponderEnabled,
					(mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""),
					(mailbox.ResponderMessage != null ? mailbox.ResponderMessage : ""));

				if (!result.Result)
					throw new Exception(result.Message);

			}
			catch (Exception ex)
			{
				if (AccountExists(mailbox.Name))
				{
					DeleteAccount(mailbox.Name);
				}
				Log.WriteError(ex);
				throw new Exception("Could not create mailbox", ex);
			}
		}
示例#10
0
		public override void UpdateAccount(MailAccount mailbox)
		{
			try
			{
                //get original account
                MailAccount account = GetAccount(mailbox.Name);  
				               
                svcUserAdmin users = new svcUserAdmin();
				PrepareProxy(users);

                
                
                string strPassword = mailbox.Password;
                
                //Don't change password. Get it from mail server.
                if (!mailbox.ChangePassword)
                {                
                    strPassword = account.Password;                                                            
                }

                GenericResult1 result = users.UpdateUser(AdminUsername, AdminPassword,
                                                             mailbox.Name,
                                                             strPassword,
                                                             mailbox.FirstName,
                                                             mailbox.LastName,
                                                             account.IsDomainAdmin
                        );                    

                if (!result.Result)
					throw new Exception(result.Message);

				// set forwarding settings
				result = users.UpdateUserForwardingInfo(AdminUsername, AdminPassword,
					mailbox.Name, mailbox.DeleteOnForward,
					(mailbox.ForwardingAddresses != null ? String.Join(", ", mailbox.ForwardingAddresses) : ""));

				if (!result.Result)
					throw new Exception(result.Message);

				// set additional settings
				result = users.SetRequestedUserSettings(AdminUsername, AdminPassword,
					mailbox.Name,
					new string[]
                    {
                        "isenabled=" + mailbox.Enabled.ToString(),
                        "maxsize=" + mailbox.MaxMailboxSize.ToString(),
                        "passwordlocked=" + mailbox.PasswordLocked.ToString(),
                        "replytoaddress=" + (mailbox.ReplyTo != null ? mailbox.ReplyTo : ""),
                        "signature=" + (mailbox.Signature != null ? mailbox.Signature : ""),
						"spamforwardoption=none"
                    });

				if (!result.Result)
					throw new Exception(result.Message);

				// set autoresponder settings
				result = users.UpdateUserAutoResponseInfo(AdminUsername, AdminPassword,
					mailbox.Name,
					mailbox.ResponderEnabled,
					(mailbox.ResponderSubject != null ? mailbox.ResponderSubject : ""),
					(mailbox.ResponderMessage != null ? mailbox.ResponderMessage : ""));

				if (!result.Result)
					throw new Exception(result.Message);
			}
			catch (Exception ex)
			{
				throw new Exception("Could not update mailbox", ex);
			}
		}