public string GetAccountImage(int accountTypeId)
        {
            string imgName = string.Empty;

            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;

            switch (accountType)
            {
            case ExchangeAccountType.Room:
                imgName = "room_16.gif";
                break;

            case ExchangeAccountType.Equipment:
                imgName = "equipment_16.gif";
                break;

            case ExchangeAccountType.SecurityGroup:
                imgName = "dlist_16.gif";
                break;

            case ExchangeAccountType.DefaultSecurityGroup:
                imgName = "dlist_16.gif";
                break;

            default:
                imgName = "admin_16.png";
                break;
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
Пример #2
0
        private void UpdateGridViewAccounts(GridView gv)
        {
            CheckBox chkSelectAll = (CheckBox)gv.HeaderRow.FindControl("chkSelectAll");

            for (int i = 0; i < gv.Rows.Count; i++)
            {
                GridViewRow row       = gv.Rows[i];
                CheckBox    chkSelect = (CheckBox)row.FindControl("chkSelect");
                if (chkSelect == null)
                {
                    continue;
                }

                ExchangeAccountType exAccountType = (ExchangeAccountType)Enum.Parse(typeof(ExchangeAccountType), ((Literal)row.FindControl("litAccountType")).Text);

                if (exAccountType != ExchangeAccountType.DefaultSecurityGroup)
                {
                    chkSelectAll      = null;
                    chkSelect.Enabled = true;
                }
                else
                {
                    chkSelect.Enabled = false;
                }
            }

            if (chkSelectAll != null)
            {
                chkSelectAll.Enabled = false;
            }
        }
        public string GetAccountImage(int accountTypeId)
        {
            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;
            string imgName = "mailbox_16.gif";

            if (accountType == ExchangeAccountType.Contact)
            {
                imgName = "contact_16.gif";
            }
            else if (accountType == ExchangeAccountType.DistributionList ||
                     accountType == ExchangeAccountType.SecurityGroup ||
                     accountType == ExchangeAccountType.DefaultSecurityGroup)
            {
                imgName = "dlist_16.gif";
            }
            else if (accountType == ExchangeAccountType.Room)
            {
                imgName = "room_16.gif";
            }
            else if (accountType == ExchangeAccountType.Equipment)
            {
                imgName = "equipment_16.gif";
            }
            else if (accountType == ExchangeAccountType.SharedMailbox)
            {
                imgName = "shared_16.gif";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
        public string GetAccountImage(int accountTypeId, bool vip)
        {
            string imgName = string.Empty;

            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;

            switch (accountType)
            {
            case ExchangeAccountType.Room:
                imgName = "room_16.gif";
                break;

            case ExchangeAccountType.Equipment:
                imgName = "equipment_16.gif";
                break;

            default:
                imgName = "admin_16.png";
                break;
            }
            if (vip && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels))
            {
                imgName = "vip_user_16.png";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
        public string GetAccountImage(int accountTypeId, bool vip)
        {
            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;
            string imgName = "mailbox_16.gif";

            if (accountType == ExchangeAccountType.Contact)
            {
                imgName = "contact_16.gif";
            }
            else if (accountType == ExchangeAccountType.DistributionList)
            {
                imgName = "dlist_16.gif";
            }
            else if (accountType == ExchangeAccountType.Room)
            {
                imgName = "room_16.gif";
            }
            else if (accountType == ExchangeAccountType.Equipment)
            {
                imgName = "equipment_16.gif";
            }
            else if (accountType == ExchangeAccountType.SharedMailbox)
            {
                imgName = "shared_16.gif";
            }

            if (vip && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels))
            {
                imgName = "vip_user_16.png";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
Пример #6
0
        public string GetAccountImage(int accountTypeId)
        {
            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;
            string imgName = "dlist_16.gif";

            return(GetThemedImage("Exchange/" + imgName));
        }
Пример #7
0
 private static int AddAccount(int itemId, ExchangeAccountType accountType,
                               string accountName, string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
                               MailboxManagerActions mailboxManagerActions, string samAccountName, string accountPassword)
 {
     return(DataProvider.AddExchangeAccount(itemId, (int)accountType,
                                            accountName, displayName, primaryEmailAddress, mailEnabledPublicFolder,
                                            mailboxManagerActions.ToString(), samAccountName, 0, string.Empty));
 }
        protected void gvObjects_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteItem")
            {
                try
                {
                    string[] arg = e.CommandArgument.ToString().Split(',');
                    if (arg.Length != 3)
                    {
                        return;
                    }

                    string[] emails = { arg[2] };

                    int accountID = 0;
                    if (!int.TryParse(arg[0], out accountID))
                    {
                        return;
                    }

                    int accountTypeID = 0;
                    if (!int.TryParse(arg[1], out accountTypeID))
                    {
                        return;
                    }

                    ExchangeAccountType accountType = (ExchangeAccountType)accountTypeID;

                    int result;

                    switch (accountType)
                    {
                    case ExchangeAccountType.Room:
                    case ExchangeAccountType.Equipment:
                    case ExchangeAccountType.SharedMailbox:
                    case ExchangeAccountType.Mailbox:
                        result = ES.Services.ExchangeServer.DeleteMailboxEmailAddresses(
                            PanelRequest.ItemID, accountID, emails);
                        break;

                    case ExchangeAccountType.DistributionList:
                        result = ES.Services.ExchangeServer.DeleteDistributionListEmailAddresses(
                            PanelRequest.ItemID, accountID, emails);
                        break;

                    case ExchangeAccountType.PublicFolder:
                        result = ES.Services.ExchangeServer.DeletePublicFolderEmailAddresses(
                            PanelRequest.ItemID, accountID, emails);
                        break;
                    }

                    Bind();
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #9
0
        public int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName,
                                 string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId,
                                 int archivedPlanId, string subscriberNumber, bool EnableArchiving)
        {
            int res = ExchangeServerController.CreateMailbox(itemId, accountId, accountType, accountName, displayName, name, domain, password,
                                                             sendSetupInstructions, setupInstructionMailAddress, mailboxPlanId, archivedPlanId, subscriberNumber, EnableArchiving);

            return(res);
        }
        public string GetAccountImage(int accountTypeId)
        {
            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;
            string imgName = "accounting_mail_16.png";

            if (accountType == ExchangeAccountType.User)
            {
                imgName = "admin_16.png";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
        public string GetMailImage(int accountTypeId)
        {
            string imgName = "exchange24.png";

            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;

            if (accountType == ExchangeAccountType.User)
            {
                imgName = "blank16.gif";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
        public bool EnableMailImageButton(int accountTypeId)
        {
            bool imgName = true;

            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;

            if (accountType == ExchangeAccountType.User)
            {
                imgName = false;
            }

            return(imgName);
        }
Пример #13
0
 private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
                                           string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
                                           string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId)
 {
     DataProvider.UpdateExchangeAccount(accountId,
                                        accountName,
                                        accountType,
                                        displayName,
                                        primaryEmailAddress,
                                        mailEnabledPublicFolder,
                                        mailboxManagerActions,
                                        samAccountName,
                                        mailboxPlanId, -1, string.Empty, false);
 }
Пример #14
0
 private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
                                           string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
                                           string mailboxManagerActions, string samAccountName, string accountPassword)
 {
     DataProvider.UpdateExchangeAccount(accountId,
                                        accountName,
                                        accountType,
                                        displayName,
                                        primaryEmailAddress,
                                        mailEnabledPublicFolder,
                                        mailboxManagerActions,
                                        samAccountName,
                                        CryptoUtils.Encrypt(accountPassword));
 }
        private void CreateMailbox()
        {
            if (!Page.IsValid)
            {
                return;
            }

            try
            {
                string name        = IsNewUser ? email.AccountName : userSelector.GetPrimaryEmailAddress().Split('@')[0];
                string displayName = IsNewUser ? txtDisplayName.Text.Trim() : userSelector.GetDisplayName();
                string accountName = IsNewUser ? string.Empty : userSelector.GetAccount();

                ExchangeAccountType type = IsNewUser
                                               ? (ExchangeAccountType)Utils.ParseInt(rbMailboxType.SelectedValue, 1)
                                               : ExchangeAccountType.Mailbox;

                string domain = IsNewUser ? email.DomainName : userSelector.GetPrimaryEmailAddress().Split('@')[1];

                int accountId = IsNewUser ? 0 : userSelector.GetAccountId();

                accountId = ES.Services.ExchangeServer.CreateMailbox(PanelRequest.ItemID, accountId, type,
                                                                     accountName,
                                                                     displayName,
                                                                     name,
                                                                     domain,
                                                                     password.Password,
                                                                     chkSendInstructions.Checked,
                                                                     sendInstructionEmail.Text);


                if (accountId < 0)
                {
                    messageBox.ShowResultMessage(accountId);
                    return;
                }

                Response.Redirect(EditUrl("AccountID", accountId.ToString(), "mailbox_settings",
                                          "SpaceID=" + PanelSecurity.PackageId.ToString(),
                                          "ItemID=" + PanelRequest.ItemID.ToString()));
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("EXCHANGE_CREATE_MAILBOX", ex);
            }
        }
        public string GetObjectType(string objectName, int objectType)
        {
            if (objectName == EXCHANGEACCOUNTS)
            {
                ExchangeAccountType accountType = (ExchangeAccountType)objectType;
                objectName = accountType.ToString();
            }

            string res = GetLocalizedString(objectName + ".Text");

            if (string.IsNullOrEmpty(res))
            {
                res = objectName;
            }

            return(res);
        }
 public bool AllowDelete(string objectName, int objectType)
 {
     if (objectName == EXCHANGEACCOUNTEMAILADDRESSES)
     {
         ExchangeAccountType accountType = (ExchangeAccountType)objectType;
         switch (accountType)
         {
         case ExchangeAccountType.Room:
         case ExchangeAccountType.Equipment:
         case ExchangeAccountType.SharedMailbox:
         case ExchangeAccountType.Mailbox:
         case ExchangeAccountType.DistributionList:
         case ExchangeAccountType.PublicFolder:
             return(true);
         }
     }
     return(false);
 }
        public string GetType(int accountTypeId)
        {
            ExchangeAccountType accountType = (ExchangeAccountType)accountTypeId;

            switch (accountType)
            {
            case ExchangeAccountType.DistributionList:
                return("Distribution");

            case ExchangeAccountType.SecurityGroup:
                return("Security");

            case ExchangeAccountType.DefaultSecurityGroup:
                return("Default");

            default:
                return(string.Empty);
            }
        }
Пример #19
0
        /// <summary>
        /// Converts value into CSV string.
        /// </summary>
        /// <param name="val">Value.</param>
        /// <returns>CSV string.</returns>
        protected static string ToCsvString(ExchangeAccountType val)
        {
            string ret = string.Empty;

            switch (val)
            {
            case ExchangeAccountType.Contact:
                ret = "Contact";
                break;

            case ExchangeAccountType.DistributionList:
                ret = "Distribution List";
                break;

            case ExchangeAccountType.Equipment:
                ret = "Equipment Mailbox";
                break;

            case ExchangeAccountType.Mailbox:
                ret = "User Mailbox";
                break;

            case ExchangeAccountType.PublicFolder:
                ret = "Public Folder";
                break;

            case ExchangeAccountType.Room:
                ret = "Room Mailbox";
                break;

            case ExchangeAccountType.User:
                ret = "User";
                break;

            default:
                ret = "Undefined";
                break;
            }
            return(ToCsvString(ret));
        }
        public string GetObjectImage(string objectName, int objectType)
        {
            string imgName = "blank16.gif";

            if (objectName == EXCHANGEACCOUNTS)
            {
                ExchangeAccountType accountType = (ExchangeAccountType)objectType;

                imgName = "mailbox_16.gif";
                switch (accountType)
                {
                case ExchangeAccountType.Contact:
                    imgName = "contact_16.gif";
                    break;

                case ExchangeAccountType.DistributionList:
                    imgName = "dlist_16.gif";
                    break;

                case ExchangeAccountType.Room:
                    imgName = "room_16.gif";
                    break;

                case ExchangeAccountType.Equipment:
                    imgName = "equipment_16.gif";
                    break;

                case ExchangeAccountType.SharedMailbox:
                    imgName = "shared_16.gif";
                    break;
                }
            }
            else if (objectName == EXCHANGEACCOUNTEMAILADDRESSES)
            {
                imgName = "mailbox_16.gif";
            }

            return(GetThemedImage("Exchange/" + imgName));
        }
Пример #21
0
 public string CreateMailbox(string organizationId, string organizationDistinguishedName, string mailboxDatabase,
                             string securityGroup, string offlineAddressBook, ExchangeAccountType accountType,
                             string displayName, string accountName, string name,
                             string domain, string password, bool enablePOP, bool enableIMAP, bool enableOWA, bool enableMAPI, bool enableActiveSync,
                             int issueWarningKB, int prohibitSendKB, int prohibitSendReceiveKB, int keepDeletedItemsDays)
 {
     try
     {
         LogStart("CreateMailbox");
         string ret = ES.CreateMailbox(organizationId, organizationDistinguishedName, mailboxDatabase, securityGroup,
                                       offlineAddressBook, accountType,
                                       displayName, accountName, name, domain, password, enablePOP, enableIMAP,
                                       enableOWA, enableMAPI, enableActiveSync,
                                       issueWarningKB, prohibitSendKB, prohibitSendReceiveKB, keepDeletedItemsDays);
         LogEnd("CreateMailbox");
         return(ret);
     }
     catch (Exception ex)
     {
         LogError("CreateMailbox", ex);
         throw;
     }
 }
 /// <remarks/>
 public void SearchAccountAsync(ExchangeAccountType accountType, string primaryEmailAddress) {
     this.SearchAccountAsync(accountType, primaryEmailAddress, null);
 }
Пример #23
0
 /// <remarks/>
 public void SearchAccountsByTypesAsync(int itemId, ExchangeAccountType[] types, string filterColumn, string filterValue, string sortColumn)
 {
     this.SearchAccountsByTypesAsync(itemId, types, filterColumn, filterValue, sortColumn, null);
 }
Пример #24
0
        /// <summary>
        /// Creates mailbox
        /// </summary>
        private bool CreateMailbox(ExchangeAccountType exchangeAccountType, int index, int orgId, string displayName, string emailAddress, string password, string firstName, string middleName, string lastName,
                                   string address, string city, string state, string zip, string country, string jobTitle, string company, string department, string office,
                                   string businessPhone, string fax, string homePhone, string mobilePhone, string pager, string webPage, string notes, int planId)
        {
            bool ret = false;

            try
            {
                string name   = emailAddress.Substring(0, emailAddress.IndexOf("@"));
                string domain = emailAddress.Substring(emailAddress.IndexOf("@") + 1);

                //create mailbox
                //ES.Services.ExchangeServer.
                string accountName = string.Empty;
                int    accountId   = ES.Services.ExchangeServer.CreateMailbox(orgId, 0, exchangeAccountType, accountName, displayName, name, domain, password, false, string.Empty, planId, -1, string.Empty, false);
                if (accountId < 0)
                {
                    string errorMessage = GetErrorMessage(accountId);
                    Log.WriteError(string.Format("Error at line {0}: {1}", index + 1, errorMessage));
                    return(false);
                }
                //ExchangeMailbox mailbox = ES.Services.ExchangeServer.GetMailboxGeneralSettings(orgId, accountId);
                OrganizationUser mailbox = ES.Services.Organizations.GetUserGeneralSettings(orgId, accountId);

                mailbox.FirstName     = firstName;
                mailbox.Initials      = middleName;
                mailbox.LastName      = lastName;
                mailbox.Address       = address;
                mailbox.City          = city;
                mailbox.State         = state;
                mailbox.Zip           = zip;
                mailbox.Country       = country;
                mailbox.JobTitle      = jobTitle;
                mailbox.Company       = company;
                mailbox.Department    = department;
                mailbox.Office        = office;
                mailbox.BusinessPhone = businessPhone;
                mailbox.Fax           = fax;
                mailbox.HomePhone     = homePhone;
                mailbox.MobilePhone   = mobilePhone;
                mailbox.Pager         = pager;
                mailbox.WebPage       = webPage;
                mailbox.Notes         = notes;

                //update mailbox

                /*
                 *              ES.Services.ExchangeServer.SetMailboxGeneralSettings(orgId, accountId, mailbox.DisplayName,
                 *                      null, mailbox.HideFromAddressBook, mailbox.Disabled, mailbox.FirstName, mailbox.Initials,
                 *                      mailbox.LastName, mailbox.Address, mailbox.City, mailbox.State, mailbox.Zip, mailbox.Country,
                 *                      mailbox.JobTitle, mailbox.Company, mailbox.Department, mailbox.Office, null, mailbox.BusinessPhone,
                 *                      mailbox.Fax, mailbox.HomePhone, mailbox.MobilePhone, mailbox.Pager, mailbox.WebPage, mailbox.Notes);
                 */
                ES.Services.Organizations.SetUserGeneralSettings(orgId, accountId, mailbox.DisplayName,
                                                                 null, /*mailbox.HideFromAddressBook*/ false, mailbox.Disabled, mailbox.Locked, mailbox.FirstName, mailbox.Initials,
                                                                 mailbox.LastName, mailbox.Address, mailbox.City, mailbox.State, mailbox.Zip, mailbox.Country,
                                                                 mailbox.JobTitle, mailbox.Company, mailbox.Department, mailbox.Office, null, mailbox.BusinessPhone,
                                                                 mailbox.Fax, mailbox.HomePhone, mailbox.MobilePhone, mailbox.Pager, mailbox.WebPage, mailbox.Notes,
                                                                 // these are new and not in csv ...
                                                                 mailbox.ExternalEmail, mailbox.SubscriberNumber, mailbox.LevelId, mailbox.IsVIP, false);
                ret = true;
            }
            catch (Exception ex)
            {
                Log.WriteError(string.Format("Error at line {0}: Unable to create mailbox", index + 1), ex);
            }
            return(ret);
        }
Пример #25
0
 public string CreateMailEnableUser(string upn, string organizationId, string organizationDistinguishedName, ExchangeAccountType accountType,
                                    string mailboxDatabase, string offlineAddressBook,
                                    string accountName, bool enablePOP, bool enableIMAP,
                                    bool enableOWA, bool enableMAPI, bool enableActiveSync,
                                    int issueWarningKB, int prohibitSendKB, int prohibitSendReceiveKB, int keepDeletedItemsDays)
 {
     try
     {
         LogStart("CreateMailEnableUser");
         string ret = ES.CreateMailEnableUser(upn, organizationId, organizationDistinguishedName, accountType,
                                              mailboxDatabase, offlineAddressBook,
                                              accountName, enablePOP, enableIMAP,
                                              enableOWA, enableMAPI, enableActiveSync,
                                              issueWarningKB, prohibitSendKB, prohibitSendReceiveKB,
                                              keepDeletedItemsDays);
         LogEnd("CreateMailEnableUser");
         return(ret);
     }
     catch (Exception ex)
     {
         LogError("ExtendToExchangeOrganization", ex);
         throw;
     }
 }
Пример #26
0
 public ExchangeAccount SearchAccount(ExchangeAccountType accountType, string primaryEmailAddress)
 {
     return(ExchangeServerController.SearchAccount(accountType, primaryEmailAddress));
 }
 /// <remarks/>
 public void CreateMailboxAsync(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving, object userState) {
     if ((this.CreateMailboxOperationCompleted == null)) {
         this.CreateMailboxOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateMailboxOperationCompleted);
     }
     this.InvokeAsync("CreateMailbox", new object[] {
                 itemId,
                 accountId,
                 accountType,
                 accountName,
                 displayName,
                 name,
                 domain,
                 password,
                 sendSetupInstructions,
                 setupInstructionMailAddress,
                 mailboxPlanId,
                 archivedPlanId,
                 subscriberNumber,
                 EnableArchiving}, this.CreateMailboxOperationCompleted, userState);
 }
 /// <remarks/>
 public System.IAsyncResult BeginCreateMailbox(
             int itemId, 
             int accountId, 
             ExchangeAccountType accountType, 
             string accountName, 
             string displayName, 
             string name, 
             string domain, 
             string password, 
             bool sendSetupInstructions, 
             string setupInstructionMailAddress, 
             int mailboxPlanId, 
             int archivedPlanId, 
             string subscriberNumber, 
             bool EnableArchiving, 
             System.AsyncCallback callback, 
             object asyncState) {
     return this.BeginInvoke("CreateMailbox", new object[] {
                 itemId,
                 accountId,
                 accountType,
                 accountName,
                 displayName,
                 name,
                 domain,
                 password,
                 sendSetupInstructions,
                 setupInstructionMailAddress,
                 mailboxPlanId,
                 archivedPlanId,
                 subscriberNumber,
                 EnableArchiving}, callback, asyncState);
 }
Пример #29
0
 public static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
     string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
     string mailboxManagerActions, string samAccountName, int mailboxPlanId, int archivePlanId, string subscriberNumber,
     bool EnableArchiving)
 {
     SqlHelper.ExecuteNonQuery(
         ConnectionString,
         CommandType.StoredProcedure,
         "UpdateExchangeAccount",
         new SqlParameter("@AccountID", accountId),
         new SqlParameter("@AccountName", accountName),
         new SqlParameter("@DisplayName", displayName),
         new SqlParameter("@AccountType", (int)accountType),
         new SqlParameter("@PrimaryEmailAddress", primaryEmailAddress),
         new SqlParameter("@MailEnabledPublicFolder", mailEnabledPublicFolder),
         new SqlParameter("@MailboxManagerActions", mailboxManagerActions),
         new SqlParameter("@SamAccountName", samAccountName),
         new SqlParameter("@MailboxPlanId", (mailboxPlanId == 0) ? (object)DBNull.Value : (object)mailboxPlanId),
         new SqlParameter("@ArchivingMailboxPlanId", (archivePlanId < 1) ? (object)DBNull.Value : (object)archivePlanId),
         new SqlParameter("@SubscriberNumber", (string.IsNullOrEmpty(subscriberNumber) ? (object)DBNull.Value : (object)subscriberNumber)),
         new SqlParameter("@EnableArchiving", EnableArchiving)
     );
 }
Пример #30
0
		/// <summary>
		/// Creates mailbox
		/// </summary>
        private bool CreateMailbox(ExchangeAccountType exchangeAccountType, int index, int orgId, string displayName, string emailAddress, string password, string firstName, string middleName, string lastName,
								string address, string city, string state, string zip, string country, string jobTitle, string company, string department, string office,
								string businessPhone, string fax, string homePhone, string mobilePhone, string pager, string webPage, string notes, int planId)
		{
			bool ret = false;
			try
			{
				string name = emailAddress.Substring(0, emailAddress.IndexOf("@"));
				string domain = emailAddress.Substring(emailAddress.IndexOf("@") + 1);

				//create mailbox
				//ES.Services.ExchangeServer.
				string accountName = string.Empty;
                int accountId = ES.Services.ExchangeServer.CreateMailbox(orgId, 0, exchangeAccountType, accountName, displayName, name, domain, password, false, string.Empty, planId, -1, string.Empty, false);
				if (accountId < 0)
				{
					string errorMessage = GetErrorMessage(accountId);
					Log.WriteError(string.Format("Error at line {0}: {1}", index + 1, errorMessage));
					return false;
				}
                //ExchangeMailbox mailbox = ES.Services.ExchangeServer.GetMailboxGeneralSettings(orgId, accountId);
                OrganizationUser mailbox = ES.Services.Organizations.GetUserGeneralSettings(orgId, accountId);

				mailbox.FirstName = firstName;
				mailbox.Initials = middleName;
				mailbox.LastName = lastName;
				mailbox.Address = address;
				mailbox.City = city;
				mailbox.State = state;
				mailbox.Zip = zip;
				mailbox.Country = country;
				mailbox.JobTitle = jobTitle;
				mailbox.Company = company;
				mailbox.Department = department;
				mailbox.Office = office;
				mailbox.BusinessPhone = businessPhone;
				mailbox.Fax = fax;
				mailbox.HomePhone = homePhone;
				mailbox.MobilePhone = mobilePhone;
				mailbox.Pager = pager;
				mailbox.WebPage = webPage;
				mailbox.Notes = notes;

				//update mailbox
                /*
				ES.Services.ExchangeServer.SetMailboxGeneralSettings(orgId, accountId, mailbox.DisplayName,
					null, mailbox.HideFromAddressBook, mailbox.Disabled, mailbox.FirstName, mailbox.Initials,
					mailbox.LastName, mailbox.Address, mailbox.City, mailbox.State, mailbox.Zip, mailbox.Country,
					mailbox.JobTitle, mailbox.Company, mailbox.Department, mailbox.Office, null, mailbox.BusinessPhone,
					mailbox.Fax, mailbox.HomePhone, mailbox.MobilePhone, mailbox.Pager, mailbox.WebPage, mailbox.Notes);
                */
                ES.Services.Organizations.SetUserGeneralSettings(orgId, accountId, mailbox.DisplayName,
                    null, /*mailbox.HideFromAddressBook*/ false, mailbox.Disabled, mailbox.Locked, mailbox.FirstName, mailbox.Initials,
                    mailbox.LastName, mailbox.Address, mailbox.City, mailbox.State, mailbox.Zip, mailbox.Country,
                    mailbox.JobTitle, mailbox.Company, mailbox.Department, mailbox.Office, null, mailbox.BusinessPhone,
                    mailbox.Fax, mailbox.HomePhone, mailbox.MobilePhone, mailbox.Pager, mailbox.WebPage, mailbox.Notes,
                    // these are new and not in csv ...
                    mailbox.ExternalEmail, mailbox.SubscriberNumber,mailbox.LevelId, mailbox.IsVIP, false);
                ret = true;
			}
			catch (Exception ex)
			{
				Log.WriteError(string.Format("Error at line {0}: Unable to create mailbox", index + 1), ex);
			}
			return ret;
		}
Пример #31
0
        private static int AddMailbox(int itemId, DirectoryEntry entry)
        {
            string accountName = (string)entry.Properties["name"].Value;

            Log.WriteStart(string.Format("Importing user {0}...", accountName));

            Organization org = (Organization)PackageController.GetPackageItem(itemId);

            if (org == null)
            {
                return(-1);
            }

            // e-mail
            string email = (string)entry.Properties["userPrincipalName"].Value;

            if (string.IsNullOrEmpty(email))
            {
                throw new Exception("UPN is not specified");
            }

            if (EmailAddressExists(email))
            {
                return(BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS);
            }

            if (AccountExists(accountName))
            {
                throw new Exception(string.Format("Account {0} already exists", accountName));
            }

            string displayName = (string)entry.Properties["displayName"].Value;

            string samName = (string)entry.Properties["sAMAccountName"].Value;

            // this should really NEVER happen - an AD account without sAMAccountName?!
            if (string.IsNullOrEmpty(samName))
            {
                throw new Exception("SAMAccountName is not specified");
            }
            // add Netbios-Domainname before samAccountName - format in the database
            samName = Global.NetBiosDomain + "\\" + samName;

            int userId = AddOrganizationUser(itemId, accountName, displayName, email, samName, string.Empty);

            AddAccountEmailAddress(userId, email);

            //account type
            PropertyValueCollection type = entry.Properties["msExchRecipientDisplayType"];

            if (type == null || type.Value == null)
            {
                Log.WriteInfo("Account type : user");
                return(userId);
            }
            int mailboxType = (int)type.Value;

            int mailboxTypeDetails = 0;
            PropertyValueCollection typeDetails = entry.Properties["msExchRecipientTypeDetails"];

            if (typeDetails != null)
            {
                if (typeDetails.Value != null)
                {
                    try
                    {
                        object adsLargeInteger = typeDetails.Value;
                        mailboxTypeDetails = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
                    }
                    catch { } // just skip
                }
            }

            ExchangeAccountType accountType = ExchangeAccountType.Undefined;

            if (mailboxTypeDetails == 4)
            {
                Log.WriteInfo("Account type : shared mailbox");
                accountType = ExchangeAccountType.SharedMailbox;
            }
            else
            {
                switch (mailboxType)
                {
                case 1073741824:
                    Log.WriteInfo("Account type : mailbox");
                    accountType = ExchangeAccountType.Mailbox;
                    break;

                case 7:
                    Log.WriteInfo("Account type : room");
                    accountType = ExchangeAccountType.Room;
                    break;

                case 8:
                    Log.WriteInfo("Account type : equipment");
                    accountType = ExchangeAccountType.Equipment;
                    break;

                default:
                    Log.WriteInfo("Account type : unknown");
                    return(userId);
                }
            }

            UpdateExchangeAccount(userId, accountName, accountType, displayName, email, false, string.Empty, samName, string.Empty, Global.defaultMailboxPlanId);

            string defaultEmail = (string)entry.Properties["extensionAttribute3"].Value;

            PropertyValueCollection emails = entry.Properties["proxyAddresses"];

            if (emails != null)
            {
                foreach (string mail in emails)
                {
                    string emailAddress = mail;
                    if (emailAddress.ToLower().StartsWith("smtp:"))
                    {
                        emailAddress = emailAddress.Substring(5);
                    }

                    if (EmailAddressExists(emailAddress))
                    {
                        if ((!emailAddress.Equals(defaultEmail, StringComparison.InvariantCultureIgnoreCase)) && (!emailAddress.Equals(email, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            Log.WriteInfo(string.Format("Email address {0} already exists. Skipped", emailAddress));
                        }

                        continue;
                    }
                    // register email address
                    Log.WriteInfo(string.Format("Importing email {0}", emailAddress));
                    AddAccountEmailAddress(userId, emailAddress);
                }
            }
            Log.WriteEnd("User imported");
            return(userId);
        }
 public int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName,
     string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving)
 {
     return ExchangeServerController.CreateMailbox(itemId, accountId, accountType, accountName, displayName, name, domain, password, sendSetupInstructions, setupInstructionMailAddress, mailboxPlanId, archivedPlanId, subscriberNumber, EnableArchiving);
 }
Пример #33
0
 /// <remarks/>
 public System.IAsyncResult BeginSearchAccountsByTypes(int itemId, ExchangeAccountType[] types, string filterColumn, string filterValue, string sortColumn, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("SearchAccountsByTypes", new object[] {
                 itemId,
                 types,
                 filterColumn,
                 filterValue,
                 sortColumn}, callback, asyncState);
 }
 /// <remarks/>
 public void SearchAccountAsync(ExchangeAccountType accountType, string primaryEmailAddress, object userState) {
     if ((this.SearchAccountOperationCompleted == null)) {
         this.SearchAccountOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchAccountOperationCompleted);
     }
     this.InvokeAsync("SearchAccount", new object[] {
                 accountType,
                 primaryEmailAddress}, this.SearchAccountOperationCompleted, userState);
 }
 public int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving) {
     object[] results = this.Invoke("CreateMailbox", new object[] {
                 itemId,
                 accountId,
                 accountType,
                 accountName,
                 displayName,
                 name,
                 domain,
                 password,
                 sendSetupInstructions,
                 setupInstructionMailAddress,
                 mailboxPlanId,
                 archivedPlanId,
                 subscriberNumber,
                 EnableArchiving});
     return ((int)(results[0]));
 }
        public static ExchangeAccount SearchAccount(ExchangeAccountType accountType, string primaryEmailAddress)
        {
            ExchangeAccount account = ObjectUtils.FillObjectFromDataReader<ExchangeAccount>(
                DataProvider.SearchExchangeAccount(SecurityContext.User.UserId,
                (int)accountType, primaryEmailAddress));

            if (account == null)
                return null;

            return account;
        }
 /// <remarks/>
 public void CreateMailboxAsync(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving) {
     this.CreateMailboxAsync(itemId, accountId, accountType, accountName, displayName, name, domain, password, sendSetupInstructions, setupInstructionMailAddress, mailboxPlanId, archivedPlanId, subscriberNumber, EnableArchiving, null);
 }
 private static void UpdateExchangeAccount(int accountId, string accountName, ExchangeAccountType accountType,
     string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
     string mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, int archivePlanId, string subscriberNumber,
     bool EnableArchiving)
 {
     DataProvider.UpdateExchangeAccount(accountId,
         accountName,
         accountType,
         displayName,
         primaryEmailAddress,
         mailEnabledPublicFolder,
         mailboxManagerActions,
         samAccountName,
         mailboxPlanId, archivePlanId,
         (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()), EnableArchiving);
 }
Пример #39
0
 public List <ExchangeAccount> GetAccounts(int itemId, ExchangeAccountType accountType)
 {
     return(ExchangeServerController.GetAccounts(itemId, accountType));
 }
Пример #40
0
		public string CreateMailbox(string organizationId, string organizationDistinguishedName, string mailboxDatabase,
			string securityGroup, string offlineAddressBook, ExchangeAccountType accountType,
			string displayName, string accountName, string name,
			string domain, string password, bool enablePOP, bool enableIMAP, bool enableOWA, bool enableMAPI, bool enableActiveSync,
			int issueWarningKB, int prohibitSendKB, int prohibitSendReceiveKB, int keepDeletedItemsDays)
		{
			try
			{
				LogStart("CreateMailbox");
				string ret = ES.CreateMailbox(organizationId, organizationDistinguishedName, mailboxDatabase, securityGroup,
					offlineAddressBook, accountType,
					displayName, accountName, name, domain, password, enablePOP, enableIMAP,
					enableOWA, enableMAPI, enableActiveSync,
					issueWarningKB, prohibitSendKB, prohibitSendReceiveKB, keepDeletedItemsDays);
				LogEnd("CreateMailbox");
				return ret;
			}
			catch (Exception ex)
			{
				LogError("CreateMailbox", ex);
				throw;
			}
		}
Пример #41
0
        internal override string CreateMailEnableUserInternal(string upn, string organizationId, string organizationDistinguishedName,
            ExchangeAccountType accountType,
            string mailboxDatabase, string offlineAddressBook, string addressBookPolicy,
            string accountName, bool enablePOP, bool enableIMAP,
            bool enableOWA, bool enableMAPI, bool enableActiveSync,
            long issueWarningKB, long prohibitSendKB, long prohibitSendReceiveKB, int keepDeletedItemsDays,
            int maxRecipients, int maxSendMessageSizeKB, int maxReceiveMessageSizeKB, bool hideFromAddressBook, bool IsConsumer, bool enabledLitigationHold, long recoverabelItemsSpace, long recoverabelItemsWarning)
        {

            ExchangeLog.LogStart("CreateMailEnableUserInternal");
            ExchangeLog.DebugInfo("Organization Id: {0}", organizationId);

            string ret = null;
            ExchangeTransaction transaction = StartTransaction();
            Runspace runSpace = null;

            int attempts = 0;
            string id = null;

            try
            {
                runSpace = OpenRunspace();
                Command cmd = null;
                Collection<PSObject> result = null;

                //try to enable mail user for 10 times
                while (true)
                {
                    try
                    {
                        //create mailbox
                        cmd = new Command("Enable-Mailbox");
                        cmd.Parameters.Add("Identity", upn);
                        cmd.Parameters.Add("Alias", accountName);
                        string database = GetDatabase(runSpace, PrimaryDomainController, mailboxDatabase);
                        ExchangeLog.DebugInfo("database: " + database);
                        if (database != string.Empty)
                        {
                            cmd.Parameters.Add("Database", database);
                        }
                        if (accountType == ExchangeAccountType.Equipment)
                            cmd.Parameters.Add("Equipment");
                        else if (accountType == ExchangeAccountType.Room)
                            cmd.Parameters.Add("Room");
                        else if (accountType == ExchangeAccountType.SharedMailbox)
                            cmd.Parameters.Add("Shared");

                        result = ExecuteShellCommand(runSpace, cmd);

                        id = CheckResultObjectDN(result);
                    }
                    catch (Exception ex)
                    {
                        ExchangeLog.LogError(ex);
                    }
                    if (id != null)
                        break;

                    if (attempts > 9)
                        throw new Exception(
                            string.Format("Could not enable mail user '{0}' ", upn));

                    attempts++;
                    ExchangeLog.LogWarning("Attempt #{0} to enable mail user failed!", attempts);
                    // wait 5 sec
                    System.Threading.Thread.Sleep(1000);
                }

                transaction.RegisterEnableMailbox(id);

                string windowsEmailAddress = ObjToString(GetPSObjectProperty(result[0], "WindowsEmailAddress"));

                //update mailbox
                cmd = new Command("Set-Mailbox");
                cmd.Parameters.Add("Identity", id);
                cmd.Parameters.Add("OfflineAddressBook", offlineAddressBook);
                cmd.Parameters.Add("EmailAddressPolicyEnabled", false);
                cmd.Parameters.Add("CustomAttribute1", organizationId);
                cmd.Parameters.Add("CustomAttribute3", windowsEmailAddress);
                cmd.Parameters.Add("PrimarySmtpAddress", upn);
                cmd.Parameters.Add("WindowsEmailAddress", upn);

                cmd.Parameters.Add("UseDatabaseQuotaDefaults", new bool?(false));
                cmd.Parameters.Add("UseDatabaseRetentionDefaults", false);
                cmd.Parameters.Add("IssueWarningQuota", ConvertKBToUnlimited(issueWarningKB));
                cmd.Parameters.Add("ProhibitSendQuota", ConvertKBToUnlimited(prohibitSendKB));
                cmd.Parameters.Add("ProhibitSendReceiveQuota", ConvertKBToUnlimited(prohibitSendReceiveKB));
                cmd.Parameters.Add("RetainDeletedItemsFor", ConvertDaysToEnhancedTimeSpan(keepDeletedItemsDays));
                cmd.Parameters.Add("RecipientLimits", ConvertInt32ToUnlimited(maxRecipients));
                cmd.Parameters.Add("MaxSendSize", ConvertKBToUnlimited(maxSendMessageSizeKB));
                cmd.Parameters.Add("MaxReceiveSize", ConvertKBToUnlimited(maxReceiveMessageSizeKB));
                if (IsConsumer) cmd.Parameters.Add("HiddenFromAddressListsEnabled", true);
                else
                    cmd.Parameters.Add("HiddenFromAddressListsEnabled", hideFromAddressBook);
                cmd.Parameters.Add("AddressBookPolicy", addressBookPolicy);

                if (enabledLitigationHold)
                {
                    cmd.Parameters.Add("LitigationHoldEnabled", true);
                    cmd.Parameters.Add("RecoverableItemsQuota", ConvertKBToUnlimited(recoverabelItemsSpace));
                    cmd.Parameters.Add("RecoverableItemsWarningQuota", ConvertKBToUnlimited(recoverabelItemsWarning));
                }

                ExecuteShellCommand(runSpace, cmd);

                //Client Access
                cmd = new Command("Set-CASMailbox");
                cmd.Parameters.Add("Identity", id);
                cmd.Parameters.Add("ActiveSyncEnabled", enableActiveSync);
                if (enableActiveSync)
                {
                    cmd.Parameters.Add("ActiveSyncMailboxPolicy", organizationId);
                }
                cmd.Parameters.Add("OWAEnabled", enableOWA);
                cmd.Parameters.Add("MAPIEnabled", enableMAPI);
                cmd.Parameters.Add("PopEnabled", enablePOP);
                cmd.Parameters.Add("ImapEnabled", enableIMAP);
                ExecuteShellCommand(runSpace, cmd);

                //calendar settings
                if (accountType == ExchangeAccountType.Equipment || accountType == ExchangeAccountType.Room)
                {
                    SetCalendarSettings(runSpace, id);
                }

                //add to the security group
                cmd = new Command("Add-DistributionGroupMember");
                cmd.Parameters.Add("Identity", organizationId);
                cmd.Parameters.Add("Member", id);
                cmd.Parameters.Add("BypassSecurityGroupManagerCheck", true);
                ExecuteShellCommand(runSpace, cmd);

                if (!IsConsumer)
                {
                    //Set-MailboxFolderPermission for calendar
                    cmd = new Command("Add-MailboxFolderPermission");
                    cmd.Parameters.Add("Identity", id + ":\\calendar");
                    cmd.Parameters.Add("AccessRights", "Reviewer");
                    cmd.Parameters.Add("User", organizationId);
                    ExecuteShellCommand(runSpace, cmd);
                }
                cmd = new Command("Set-MailboxFolderPermission");
                cmd.Parameters.Add("Identity", id + ":\\calendar");
                cmd.Parameters.Add("AccessRights", "None");
                cmd.Parameters.Add("User", "Default");
                ExecuteShellCommand(runSpace, cmd);

                ret = string.Format("{0}\\{1}", GetNETBIOSDomainName(), accountName);
                ExchangeLog.LogEnd("CreateMailEnableUserInternal");
                return ret;
            }
            catch (Exception ex)
            {
                ExchangeLog.LogError("CreateMailEnableUserInternal", ex);
                RollbackTransaction(transaction);
                throw;
            }
            finally
            {
                CloseRunspace(runSpace);
            }
        }
        public string GetEditUrl(string objectName, int objectType, string objectId, string ownerId)
        {
            if (objectName == EXCHANGEACCOUNTS)
            {
                string key = "";

                ExchangeAccountType accountType = (ExchangeAccountType)objectType;

                switch (accountType)
                {
                case ExchangeAccountType.User:
                    key = "edit_user";
                    return(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), key,
                                   "AccountID=" + objectId,
                                   "ItemID=" + PanelRequest.ItemID, "context=user"));

                case ExchangeAccountType.Mailbox:
                case ExchangeAccountType.Room:
                case ExchangeAccountType.Equipment:
                case ExchangeAccountType.SharedMailbox:
                    key = "mailbox_settings";
                    break;

                case ExchangeAccountType.DistributionList:
                    key = "dlist_settings";
                    break;

                case ExchangeAccountType.PublicFolder:
                    key = "public_folder_settings";
                    break;

                case ExchangeAccountType.SecurityGroup:
                case ExchangeAccountType.DefaultSecurityGroup:
                    key = "secur_group_settings";
                    break;
                }

                if (!string.IsNullOrEmpty(key))
                {
                    return(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), key,
                                   "AccountID=" + objectId,
                                   "ItemID=" + PanelRequest.ItemID));
                }
            }

            if (objectName == EXCHANGEACCOUNTEMAILADDRESSES)
            {
                string key = "";

                ExchangeAccountType accountType = (ExchangeAccountType)objectType;

                switch (accountType)
                {
                case ExchangeAccountType.Mailbox:
                case ExchangeAccountType.Room:
                case ExchangeAccountType.Equipment:
                case ExchangeAccountType.SharedMailbox:
                    key = "mailbox_addresses";
                    break;

                case ExchangeAccountType.DistributionList:
                    key = "dlist_addresses";
                    break;

                case ExchangeAccountType.PublicFolder:
                    key = "public_folder_addresses";
                    break;
                }

                if (!string.IsNullOrEmpty(key))
                {
                    return(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), key,
                                   "AccountID=" + ownerId,
                                   "ItemID=" + PanelRequest.ItemID));
                }
            }

            if (objectName == LYNCUSERS)
            {
                return(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "edit_lync_user",
                               "AccountID=" + objectId,
                               "ItemID=" + PanelRequest.ItemID));
            }

            return("");
        }
Пример #43
0
        private static int AddMailbox(int itemId, DirectoryEntry entry)
        {
            string accountName = (string)entry.Properties["name"].Value;

            Log.WriteStart(string.Format("Importing user {0}...", accountName));

            Organization org = (Organization)PackageController.GetPackageItem(itemId);

            if (org == null)
            {
                return(-1);
            }

            // e-mail
            string email = (string)entry.Properties["userPrincipalName"].Value;

            if (string.IsNullOrEmpty(email))
            {
                throw new Exception("UPN is not specified");
            }

            if (EmailAddressExists(email))
            {
                return(BusinessErrorCodes.ERROR_EXCHANGE_EMAIL_EXISTS);
            }



            if (AccountExists(accountName))
            {
                throw new Exception(string.Format("Account {0} already exists", accountName));
            }

            string displayName = (string)entry.Properties["displayName"].Value;


            int userId = AddOrganizationUser(itemId, accountName, displayName, email, string.Empty);

            AddAccountEmailAddress(userId, email);

            //account type
            PropertyValueCollection type = entry.Properties["msExchRecipientDisplayType"];

            if (type == null || type.Value == null)
            {
                Log.WriteInfo("Account type : user");
                return(userId);
            }
            int mailboxType = (int)type.Value;
            ExchangeAccountType accountType = ExchangeAccountType.Undefined;

            switch (mailboxType)
            {
            case 1073741824:
                Log.WriteInfo("Account type : mailbox");
                accountType = ExchangeAccountType.Mailbox;
                break;

            case 7:
                Log.WriteInfo("Account type : room");
                accountType = ExchangeAccountType.Room;
                break;

            case 8:
                Log.WriteInfo("Account type : equipment");
                accountType = ExchangeAccountType.Equipment;
                break;

            default:
                Log.WriteInfo("Account type : unknown");
                return(userId);
            }

            UpdateExchangeAccount(userId, accountName, accountType, displayName, email, false, string.Empty, string.Empty, string.Empty);

            string defaultEmail = (string)entry.Properties["extensionAttribute3"].Value;

            PropertyValueCollection emails = entry.Properties["proxyAddresses"];

            if (emails != null)
            {
                foreach (string mail in emails)
                {
                    string emailAddress = mail;
                    if (emailAddress.ToLower().StartsWith("smtp:"))
                    {
                        emailAddress = emailAddress.Substring(5);
                    }


                    if (!emailAddress.Equals(defaultEmail, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (EmailAddressExists(emailAddress))
                        {
                            Log.WriteInfo(string.Format("Email address {0} already exists. Skipped", emailAddress));
                            continue;
                        }
                        // register email address
                        Log.WriteInfo(string.Format("Importing email {0}", emailAddress));
                        AddAccountEmailAddress(userId, emailAddress);
                    }
                }
            }
            Log.WriteEnd("User imported");
            return(userId);
        }
Пример #44
0
 /// <remarks/>
 public void SearchAccountsByTypesAsync(int itemId, ExchangeAccountType[] types, string filterColumn, string filterValue, string sortColumn, object userState)
 {
     if ((this.SearchAccountsByTypesOperationCompleted == null)) {
         this.SearchAccountsByTypesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchAccountsByTypesOperationCompleted);
     }
     this.InvokeAsync("SearchAccountsByTypes", new object[] {
                 itemId,
                 types,
                 filterColumn,
                 filterValue,
                 sortColumn}, this.SearchAccountsByTypesOperationCompleted, userState);
 }
 public ExchangeAccount SearchAccount(ExchangeAccountType accountType, string primaryEmailAddress) {
     object[] results = this.Invoke("SearchAccount", new object[] {
                 accountType,
                 primaryEmailAddress});
     return ((ExchangeAccount)(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult BeginSearchAccount(ExchangeAccountType accountType, string primaryEmailAddress, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("SearchAccount", new object[] {
                 accountType,
                 primaryEmailAddress}, callback, asyncState);
 }
Пример #47
0
		public List<ExchangeAccount> GetAccounts(int itemId, ExchangeAccountType accountType)
		{
			return ExchangeServerController.GetAccounts(itemId, accountType);
		}
Пример #48
0
 public ExchangeAccount[] SearchAccountsByTypes(int itemId, ExchangeAccountType[] types, string filterColumn, string filterValue, string sortColumn)
 {
     object[] results = this.Invoke("SearchAccountsByTypes", new object[] {
                 itemId,
                 types,
                 filterColumn,
                 filterValue,
                 sortColumn});
     return ((ExchangeAccount[])(results[0]));
 }
        private void CreateMailbox()
        {
            if (!Page.IsValid)
            {
                return;
            }

            try
            {
                string name        = IsNewUser ? email.AccountName : userSelector.GetPrimaryEmailAddress().Split('@')[0];
                string displayName = IsNewUser ? txtDisplayName.Text.Trim() : userSelector.GetDisplayName();
                string accountName = IsNewUser ? string.Empty : userSelector.GetAccount();

                bool enableArchive = chkEnableArchiving.Checked;

                ExchangeAccountType type = IsNewUser
                                               ? (ExchangeAccountType)Utils.ParseInt(rbMailboxType.SelectedValue, 1)
                                               : ExchangeAccountType.Mailbox;

                string domain = IsNewUser ? email.DomainName : userSelector.GetPrimaryEmailAddress().Split('@')[1];

                int accountId = IsNewUser ? 0 : userSelector.GetAccountId();

                string subscriberNumber = IsNewUser ? txtSubscriberNumber.Text.Trim() : userSelector.GetSubscriberNumber();

                var passwordString = password.Password;

                if (sendToControl.IsRequestSend && IsNewUser)
                {
                    passwordString = Membership.GeneratePassword(16, 3);
                }

                accountId = ES.Services.ExchangeServer.CreateMailbox(PanelRequest.ItemID, accountId, type,
                                                                     accountName,
                                                                     displayName,
                                                                     name,
                                                                     domain,
                                                                     passwordString,
                                                                     chkSendInstructions.Checked,
                                                                     sendInstructionEmail.Text,
                                                                     Convert.ToInt32(mailboxPlanSelector.MailboxPlanId),
                                                                     Convert.ToInt32(archivingMailboxPlanSelector.MailboxPlanId),
                                                                     subscriberNumber, enableArchive);


                if (accountId < 0)
                {
                    messageBox.ShowResultMessage(accountId);
                    return;
                }
                else
                {
                    if ((!string.IsNullOrEmpty(txtFirstName.Text)) | (!string.IsNullOrEmpty(txtLastName.Text)) | (!string.IsNullOrEmpty(txtInitials.Text)))
                    {
                        SetUserAttributes(accountId);
                    }
                }

                if (sendToControl.SendEmail && IsNewUser)
                {
                    ES.Services.Organizations.SendUserPasswordRequestEmail(PanelRequest.ItemID, accountId, "User creation", sendToControl.Email, true);
                }
                else if (sendToControl.SendMobile && IsNewUser)
                {
                    ES.Services.Organizations.SendUserPasswordRequestSms(PanelRequest.ItemID, accountId, "User creation", sendToControl.Mobile);
                }

                Response.Redirect(EditUrl("AccountID", accountId.ToString(), "mailbox_settings",
                                          "SpaceID=" + PanelSecurity.PackageId.ToString(),
                                          "ItemID=" + PanelRequest.ItemID.ToString(),
                                          "Context=Mailbox"));
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("EXCHANGE_CREATE_MAILBOX", ex);
            }
        }
Пример #50
0
 public ExchangeAccount SearchAccount(ExchangeAccountType accountType, string primaryEmailAddress)
 {
     return ExchangeServerController.SearchAccount(accountType, primaryEmailAddress);
 }
Пример #51
0
		public int CreateMailbox(int itemId, int accountId,  ExchangeAccountType accountType, string accountName, string displayName,
            string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress)
		{
            return ExchangeServerController.CreateMailbox(itemId, accountId, accountType, accountName, displayName, name, domain, password, sendSetupInstructions, setupInstructionMailAddress);
		}
 public ExchangeAccount[] GetAccounts(int itemId, ExchangeAccountType accountType) {
     object[] results = this.Invoke("GetAccounts", new object[] {
                 itemId,
                 accountType});
     return ((ExchangeAccount[])(results[0]));
 }
        public static List<ExchangeAccount> GetAccounts(int itemId, ExchangeAccountType accountType)
        {
            #region Demo Mode
            if (IsDemoMode)
            {
                if (accountType == ExchangeAccountType.Mailbox)
                    return SearchAccounts(0, true, false, false, true, true, false, "", "", "");
                else if (accountType == ExchangeAccountType.Contact)
                    return SearchAccounts(0, false, true, false, false, false, false, "", "", "");
                else if (accountType == ExchangeAccountType.DistributionList)
                    return SearchAccounts(0, false, false, true, false, false, false, "", "", "");
                else
                {
                    List<ExchangeAccount> demoAccounts = new List<ExchangeAccount>();
                    ExchangeAccount f1 = new ExchangeAccount();
                    f1.AccountId = 7;
                    f1.AccountName = "documents_fabrikam";
                    f1.AccountType = ExchangeAccountType.PublicFolder;
                    f1.DisplayName = "\\fabrikam\\Documents";
                    f1.PrimaryEmailAddress = "*****@*****.**";
                    f1.MailEnabledPublicFolder = true;
                    demoAccounts.Add(f1);

                    ExchangeAccount f2 = new ExchangeAccount();
                    f2.AccountId = 8;
                    f2.AccountName = "documents_fabrikam";
                    f2.AccountType = ExchangeAccountType.PublicFolder;
                    f2.DisplayName = "\\fabrikam\\Documents\\Legal";
                    f2.PrimaryEmailAddress = "";
                    demoAccounts.Add(f2);

                    ExchangeAccount f3 = new ExchangeAccount();
                    f3.AccountId = 9;
                    f3.AccountName = "documents_fabrikam";
                    f3.AccountType = ExchangeAccountType.PublicFolder;
                    f3.DisplayName = "\\fabrikam\\Documents\\Contracts";
                    f3.PrimaryEmailAddress = "";
                    demoAccounts.Add(f3);
                    return demoAccounts;
                }
            }
            #endregion

            return ObjectUtils.CreateListFromDataReader<ExchangeAccount>(
                DataProvider.GetExchangeAccounts(itemId, (int)accountType));
        }
 /// <remarks/>
 public System.IAsyncResult BeginGetAccounts(int itemId, ExchangeAccountType accountType, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("GetAccounts", new object[] {
                 itemId,
                 accountType}, callback, asyncState);
 }
 private static int AddAccount(int itemId, ExchangeAccountType accountType,
     string accountName, string displayName, string primaryEmailAddress, bool mailEnabledPublicFolder,
     MailboxManagerActions mailboxManagerActions, string samAccountName, string accountPassword, int mailboxPlanId, string subscriberNumber)
 {
     return DataProvider.AddExchangeAccount(itemId, (int)accountType,
         accountName, displayName, primaryEmailAddress, mailEnabledPublicFolder,
         mailboxManagerActions.ToString(), samAccountName, mailboxPlanId, (string.IsNullOrEmpty(subscriberNumber) ? null : subscriberNumber.Trim()));
 }
 /// <remarks/>
 public void GetAccountsAsync(int itemId, ExchangeAccountType accountType) {
     this.GetAccountsAsync(itemId, accountType, null);
 }
        public static int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName,
            string displayName, string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress, int mailboxPlanId, int archivedPlanId, string subscriberNumber, bool EnableArchiving)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check mailbox quota
            OrganizationStatistics orgStats = GetOrganizationStatisticsByOrganization(itemId);
            if (accountType == ExchangeAccountType.SharedMailbox)
            {
                if ((orgStats.AllocatedSharedMailboxes > -1) && (orgStats.CreatedSharedMailboxes >= orgStats.AllocatedSharedMailboxes))
                    return BusinessErrorCodes.ERROR_EXCHANGE_MAILBOXES_QUOTA_LIMIT;
            }
            else if ((accountType == ExchangeAccountType.Room) || (accountType == ExchangeAccountType.Equipment))
            {
                if ((orgStats.AllocatedResourceMailboxes > -1) && (orgStats.CreatedResourceMailboxes >= orgStats.AllocatedResourceMailboxes))
                    return BusinessErrorCodes.ERROR_EXCHANGE_MAILBOXES_QUOTA_LIMIT;
            }
            else
            {
                if ((orgStats.AllocatedMailboxes > -1) && (orgStats.CreatedMailboxes >= orgStats.AllocatedMailboxes))
                    return BusinessErrorCodes.ERROR_EXCHANGE_MAILBOXES_QUOTA_LIMIT;
            }


            // place log record
            TaskManager.StartTask("EXCHANGE", "CREATE_MAILBOX", displayName, itemId);
            
            // Log Extension
            LogExtension.WriteVariables(new {accountName, displayName});

            bool userCreated = false;
            Organization org = null;
            try
            {
                accountName = accountName.Trim();
                displayName = displayName.Trim();
                name = name.Trim();
                domain = domain.Trim();


                // load organization
                org = GetOrganization(itemId);
                if (org == null)
                    return -1;

                // e-mail
                string email = name + "@" + domain;
                bool enabled = (accountType == ExchangeAccountType.Mailbox);


                //  string accountName = string.Empty;
                //Create AD user if needed
                if (accountId == 0)
                {
                    accountId = OrganizationController.CreateUser(org.Id, displayName, name, domain, password, subscriberNumber, enabled, false, string.Empty, out accountName);
                    if (accountId > 0)
                        userCreated = true;
                }
                if (accountId < 0)
                    return accountId;

                // get mailbox settings
                Organizations orgProxy = OrganizationController.GetOrganizationProxy(org.ServiceId);
                OrganizationUser retUser = orgProxy.GetUserGeneralSettings(accountName, org.OrganizationId);


                int exchangeServiceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.Exchange);

                ExchangeServer exchange = GetExchangeServer(exchangeServiceId, org.ServiceId);


                //Create Exchange Organization
                if (string.IsNullOrEmpty(org.GlobalAddressList))
                {
                    ExtendToExchangeOrganization(ref org);

                    PackageController.UpdatePackageItem(org);
                }

                // check package
                int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive);
                if (packageCheck < 0) return packageCheck;

                //verify if the mailbox fits in the storage quota
                int maxDiskSpace = -1;
                int quotaUsed = 0;
                if (orgStats.AllocatedDiskSpace > 0)
                {
                    maxDiskSpace = orgStats.AllocatedDiskSpace;
                    quotaUsed = orgStats.UsedDiskSpace;
                }

                ExchangeMailboxPlan plan = GetExchangeMailboxPlan(itemId, mailboxPlanId);
                if (maxDiskSpace != -1)
                {
                    if (plan.MailboxSizeMB == -1)
                        return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;

                    if ((quotaUsed + plan.MailboxSizeMB) > (maxDiskSpace))
                        return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
                }

                if (plan.AllowLitigationHold)
                {
                    int maxRecoverableItemsSpace = -1;
                    int quotaRecoverableItemsUsed = 0;
                    if (orgStats.AllocatedLitigationHoldSpace > 0)
                    {
                        maxRecoverableItemsSpace = orgStats.AllocatedLitigationHoldSpace;
                        quotaRecoverableItemsUsed = orgStats.UsedLitigationHoldSpace;
                    }

                    if (maxRecoverableItemsSpace != -1)
                    {
                        if (plan.RecoverableItemsSpace == -1)
                            return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;

                        if (plan.RecoverableItemsSpace < 6144)
                            return BusinessErrorCodes.ERROR_EXCHANGE_INVALID_RECOVERABLEITEMS_QUOTA;

                        if ((quotaRecoverableItemsUsed + plan.RecoverableItemsSpace) > (maxRecoverableItemsSpace))
                            return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
                    }
                }

                if (plan.EnableArchiving)
                {
                    int maxArchivingStorage = -1;
                    int quotaArchivingStorageUsed = 0;
                    if (orgStats.AllocatedArchingStorage > 0)
                    {
                        maxArchivingStorage = orgStats.AllocatedArchingStorage;
                        quotaArchivingStorageUsed = orgStats.UsedArchingStorage;
                    }

                    if (maxArchivingStorage != -1)
                    {
                        if (plan.ArchiveSizeMB == -1)
                            return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;

                        if ((quotaArchivingStorageUsed + plan.ArchiveSizeMB) > (maxArchivingStorage))
                            return BusinessErrorCodes.ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES;
                    }
                }

                //GetServiceSettings
                StringDictionary primSettings = ServerController.GetServiceSettings(exchangeServiceId);
                PackageContext cntx = PackageController.GetPackageContext(org.PackageId);

                string samAccountName = exchange.CreateMailEnableUser(email, org.OrganizationId, org.DistinguishedName,
                                                org.SecurityGroup, org.DefaultDomain,
                                                accountType, primSettings["mailboxdatabase"],
                                                org.OfflineAddressBook,
                                                org.AddressBookPolicy,
                                                retUser.SamAccountName,
                                                plan.EnablePOP,
                                                plan.EnableIMAP,
                                                plan.EnableOWA,
                                                plan.EnableMAPI,
                                                plan.EnableActiveSync,
                                                plan.MailboxSizeMB != -1 ? (((long)plan.IssueWarningPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
                                                plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendPct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
                                                plan.MailboxSizeMB != -1 ? (((long)plan.ProhibitSendReceivePct * (long)plan.MailboxSizeMB * 1024) / 100) : -1,
                                                plan.KeepDeletedItemsDays,
                                                plan.MaxRecipients,
                                                plan.MaxSendMessageSizeKB,
                                                plan.MaxReceiveMessageSizeKB,
                                                plan.HideFromAddressBook,
                                                Convert.ToBoolean(cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue),
                                                plan.AllowLitigationHold,
                                                plan.RecoverableItemsSpace != -1 ? (plan.RecoverableItemsSpace * 1024) : -1,
                                                plan.RecoverableItemsSpace != -1 ? (((long)plan.RecoverableItemsWarningPct * (long)plan.RecoverableItemsSpace * 1024) / 100) : -1);

                MailboxManagerActions pmmActions = MailboxManagerActions.GeneralSettings
                    | MailboxManagerActions.MailFlowSettings
                    | MailboxManagerActions.AdvancedSettings
                    | MailboxManagerActions.EmailAddresses;


                UpdateExchangeAccount(accountId, accountName, accountType, displayName, email, false, pmmActions.ToString(), samAccountName, password, mailboxPlanId, archivedPlanId, subscriberNumber, EnableArchiving);

                ResultObject resPolicy = new ResultObject() { IsSuccess = true };
                SetMailBoxRetentionPolicyAndArchiving(itemId, mailboxPlanId, archivedPlanId, accountName, exchange, org.OrganizationId, resPolicy, EnableArchiving);
                if (!resPolicy.IsSuccess)
                {
                    TaskManager.WriteError("Error SetMailBoxRetentionPolicy: " + string.Join(", ", resPolicy.ErrorCodes.ToArray()));
                }
                

                // send setup instructions
                if (sendSetupInstructions)
                {
                    try
                    {
                        // send setup instructions
                        int sendResult = SendMailboxSetupInstructions(itemId, accountId, true, setupInstructionMailAddress, null);
                        if (sendResult < 0)
                            TaskManager.WriteWarning("Setup instructions were not sent. Error code: " + sendResult);
                    }
                    catch (Exception ex)
                    {
                        TaskManager.WriteError(ex);
                    }
                }

                try
                {
                    // update OAB
                    // check if this is the first mailbox within the organization
                    if (GetAccounts(itemId, ExchangeAccountType.Mailbox).Count == 1)
                        exchange.UpdateOrganizationOfflineAddressBook(org.OfflineAddressBook);
                }
                catch (Exception ex)
                {
                    TaskManager.WriteError(ex);
                }

                // Log Extension
                LogExtension.WriteVariables(new {email, samAccountName, accountId});

                return accountId;
            }
            catch (Exception ex)
            {
                //rollback AD user
                if (userCreated)
                {
                    try
                    {
                        OrganizationController.DeleteUser(org.Id, accountId);
                    }
                    catch (Exception rollbackException)
                    {
                        TaskManager.WriteError(rollbackException);
                    }
                }
                throw TaskManager.WriteError(ex);

            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
 /// <remarks/>
 public void GetAccountsAsync(int itemId, ExchangeAccountType accountType, object userState) {
     if ((this.GetAccountsOperationCompleted == null)) {
         this.GetAccountsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetAccountsOperationCompleted);
     }
     this.InvokeAsync("GetAccounts", new object[] {
                 itemId,
                 accountType}, this.GetAccountsOperationCompleted, userState);
 }
Пример #59
0
 public string CreateMailEnableUser(string upn, string organizationId, string organizationDistinguishedName, ExchangeAccountType accountType, 
     string mailboxDatabase,  string offlineAddressBook,            
     string accountName, bool enablePOP, bool enableIMAP,
     bool enableOWA, bool enableMAPI, bool enableActiveSync,
     int issueWarningKB, int prohibitSendKB, int prohibitSendReceiveKB, int keepDeletedItemsDays)
 {
     try
     {
         LogStart("CreateMailEnableUser");
         string ret = ES.CreateMailEnableUser(upn, organizationId, organizationDistinguishedName,accountType,
                                                    mailboxDatabase, offlineAddressBook,
                                                    accountName, enablePOP, enableIMAP,
                                                    enableOWA, enableMAPI, enableActiveSync,
                                                    issueWarningKB, prohibitSendKB, prohibitSendReceiveKB,
                                                    keepDeletedItemsDays);
         LogEnd("CreateMailEnableUser");
         return ret;
     }
     catch (Exception ex)
     {
         LogError("ExtendToExchangeOrganization", ex);
         throw;
     }
 }
 public int CreateMailbox(int itemId, int accountId, ExchangeAccountType accountType, string accountName, string displayName,
                          string name, string domain, string password, bool sendSetupInstructions, string setupInstructionMailAddress)
 {
     return(ExchangeServerController.CreateMailbox(itemId, accountId, accountType, accountName, displayName, name, domain, password, sendSetupInstructions, setupInstructionMailAddress));
 }