public void BindItem(MailAccount item) { chkResponderEnabled.Checked = item.ResponderEnabled; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; txtForward.Text = item.ForwardingAddresses != null ? String.Join("; ", item.ForwardingAddresses) : ""; }
private void AddAutoResponderInfo(MailAccount mailbox) { TreeNode autoresponses = deliveryConfig.ChildNodes["autoresponses"]; if (autoresponses == null) { autoresponses = new TreeNode(); autoresponses.NodeName = "autoresponses"; deliveryConfig.ChildNodes.Add(autoresponses); } autoresponses["enabled"] = mailbox.ResponderEnabled ? "1" : "0"; if (mailbox.ResponderEnabled) { autoresponses["subject"] = mailbox.ResponderSubject; autoresponses["body"] = mailbox.ResponderMessage; if (!string.IsNullOrEmpty(mailbox.ReplyTo)) { autoresponses["usereplyto"] = "1"; autoresponses["replyto"] = mailbox.ReplyTo; } else { autoresponses["usereplyto"] = "0"; autoresponses["replyto"] = string.Empty; } } else { autoresponses["subject"] = string.Empty; autoresponses["body"] = string.Empty; } }
public void SaveItem(MailAccount item) { item.ResponderEnabled = chkResponderEnabled.Checked; item.ResponderSubject = txtSubject.Text; item.ResponderMessage = txtMessage.Text; item.ForwardingAddresses = Utils.ParseDelimitedString(txtForward.Text, ';', ' ', ','); }
public void SaveItem(MailAccount item) { item.FullName = txtFullName.Text; item.IceWarpAccountType = Convert.ToInt32(ddlAccountType.SelectedValue); item.IceWarpAccountState = Convert.ToInt32(ddlAccountState.SelectedValue); item.IceWarpRespondType = Convert.ToInt32(ddlRespondType.SelectedValue); if (!string.IsNullOrWhiteSpace(txtRespondPeriodInDays.Text)) { item.RespondPeriodInDays = Convert.ToInt32(txtRespondPeriodInDays.Text); } item.RespondOnlyBetweenDates = chkRespondOnlyBetweenDates.Checked; item.RespondFrom = calRespondFrom.SelectedDate; item.RespondTo = calRespondTo.SelectedDate; item.RespondWithReplyFrom = txtRespondWithReplyFrom.Text; item.ResponderSubject = txtSubject.Text; item.ResponderMessage = txtMessage.Text; item.ForwardingEnabled = !string.IsNullOrWhiteSpace(txtForward.Text); item.ForwardingAddresses = Utils.ParseDelimitedString(txtForward.Text, ';', ' ', ','); item.DeleteOnForward = cbDeleteOnForward.Checked; item.IsDomainAdmin = cbDomainAdmin.Checked; item.DeleteOlder = cbDeleteOlder.Checked; item.DeleteOlderDays = string.IsNullOrWhiteSpace(txtDeleteOlderDays.Text) ? 0 : Convert.ToInt32(txtDeleteOlderDays.Text); item.ForwardOlder = cbForwardOlder.Checked; item.ForwardOlderDays = string.IsNullOrWhiteSpace(txtForwardOlderDays.Text) ? 0 : Convert.ToInt32(txtForwardOlderDays.Text); item.ForwardOlderTo = txtForwardOlderTo.Text; }
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); } }
public void BindItem(MailAccount item) { chkResponderEnabled.Checked = item.ResponderEnabled; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; txtForward.Text = item.ForwardingAddresses != null ? String.Join("; ", item.ForwardingAddresses) : ""; txtFirstName.Text = item.FirstName; txtLastName.Text = item.LastName; cbRetainLocalCopy.Checked = item.RetainLocalCopy; }
public void BindItem(MailAccount item) { txtFirstName.Text = item.FirstName; txtLastName.Text = item.LastName; txtSignature.Text = item.Signature; chkResponderEnabled.Checked = item.ResponderEnabled; txtReplyTo.Text = item.ReplyTo; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; txtForward.Text = item.ForwardingAddresses != null ? String.Join("; ", item.ForwardingAddresses) : ""; chkDeleteOnForward.Checked = item.DeleteOnForward; }
public void BindItem(MailAccount item) { chkResponderEnabled.Checked = item.ResponderEnabled; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; txtForward.Text = item.ForwardingAddresses[0]; chkOriginalMessage.Checked = item.RetainLocalCopy; txtFirstName.Text = item.FirstName; txtLastName.Text = item.LastName; cbSignatureEnabled.Checked = item.SignatureEnabled; txtPlainSignature.Text = item.Signature; txtHtmlSignature.Text = item.SignatureHTML; }
public void SaveItem(MailAccount item) { item.ResponderEnabled = chkResponderEnabled.Checked; item.ResponderSubject = txtSubject.Text; item.ResponderMessage = txtMessage.Text; item.ForwardingAddresses = new string[] { txtForward.Text }; item.RetainLocalCopy = chkOriginalMessage.Checked; item.FirstName = txtFirstName.Text; item.LastName = txtLastName.Text; item.SignatureEnabled = cbSignatureEnabled.Checked; item.Signature = txtPlainSignature.Text; item.SignatureHTML = txtHtmlSignature.Text; }
public void CreateAccount(MailAccount mailbox) { Tree users = AMSHelper.GetUsersConfig(); AmsMailbox accnt = new AmsMailbox(mailbox.Name); if (accnt.Load(users)) throw new Exception("Mailbox is already registered."); accnt.Read(mailbox); if (!accnt.Save(users)) throw new Exception("Couldn't create a mailbox."); }
public void SaveItem(MailAccount item) { item.FirstName = txtFirstName.Text; item.LastName = txtLastName.Text; item.Signature = txtSignature.Text; item.ResponderEnabled = chkResponderEnabled.Checked; item.ReplyTo = txtReplyTo.Text; item.ResponderSubject = txtSubject.Text; item.ResponderMessage = txtMessage.Text; item.ForwardingAddresses = Utils.ParseDelimitedString(txtForward.Text, ';', ' ', ','); item.DeleteOnForward = chkDeleteOnForward.Checked; item.ChangePassword = cbChangePassword.Checked; }
public void Read(MailAccount mailbox) { userConfig["domain"] = GetDomainName(mailbox.Name); userConfig["enabled"] = mailbox.Enabled ? "1" : "0"; userConfig["user"] = GetAccountName(mailbox.Name); userConfig["pass"] = mailbox.Password; // forwardings if (mailbox.ForwardingAddresses != null) { AddForwardingInfo(mailbox.ForwardingAddresses, mailbox.DeleteOnForward); } AddAutoResponderInfo(mailbox); }
private void BindAccounts(MailDomain item, DropDownList ddl, MailAccount[] accounts) { if (ddl.Items.Count == 0) ddl.Items.Add(new ListItem(GetLocalizedString("Text.NotSelected"), "")); foreach (MailAccount account in accounts) { int idx = account.Name.IndexOf("@"); string accountName = account.Name.Substring(0, idx); string accountDomain = account.Name.Substring(idx + 1); if (String.Compare(accountDomain, item.Name, true) == 0) ddl.Items.Add(new ListItem(account.Name, accountName)); } }
public void CreateAccount(MailAccount mailbox) { Tree users = AMSHelper.GetUsersConfig(); AmsMailbox accnt = new AmsMailbox(mailbox.Name); if (accnt.Load(users)) { throw new Exception("Mailbox is already registered."); } accnt.Read(mailbox); if (!accnt.Save(users)) { throw new Exception("Couldn't create a mailbox."); } }
public MailAccount ToMailAccount() { MailAccount account = new MailAccount(); account.Name = string.Concat(userConfig["user"], "@", userConfig["domain"]); account.Enabled = userConfig["enabled"] == "1" ? true : false; account.Password = userConfig["pass"]; // read forwardings TreeNode redirection = deliveryConfig.ChildNodes["redirection"]; if (redirection != null) { TreeNode redirections = redirection.ChildNodes["redirections"]; if (redirections != null) { List <string> list = new List <string>(); foreach (TreeNode node in redirections.ChildNodes) { list.Add(node.NodeValue); } account.ForwardingAddresses = list.ToArray(); } } // read autoresponder TreeNode autoresponses = deliveryConfig.ChildNodes["autoresponses"]; if (autoresponses != null) { account.ResponderEnabled = autoresponses["enabled"] == "1" ? true : false; account.ResponderSubject = autoresponses["subject"]; account.ResponderMessage = autoresponses["body"]; if (autoresponses["usereplyto"] == "1") { account.ReplyTo = autoresponses["replyto"]; } } return(account); }
public void SaveItem(MailAccount item) { item.Enabled = chkEnabled.Checked; item.ResponderEnabled = chkResponderEnabled.Checked; item.ResponderSubject = txtSubject.Text; item.ResponderMessage = txtMessage.Text; item.ResponderExpires = chkResponderExpires.Checked; if (txtResponderExireDate.Text.Trim().Length >= 10) { item.ResponderExpirationDate = txtResponderExireDate.Text.Trim().Substring(0, 10);} item.ForwardingEnabled = chkForwardingEnabled.Checked; if (txtForward.Text.Trim().Length > 0) { item.ForwardingAddresses = new string[] { txtForward.Text.Trim() };} item.RetainLocalCopy = chkOriginalMessage.Checked; item.FirstName = txtFirstName.Text; item.LastName = txtLastName.Text; item.SignatureEnabled = cbSignatureEnabled.Checked; item.Signature = txtPlainSignature.Text; item.SignatureHTML = txtHtmlSignature.Text; }
public void BindItem(MailAccount item) { txtFullName.Text = item.FullName; Utils.SelectListItem(ddlAccountType, item.IceWarpAccountType); Utils.SelectListItem(ddlAccountState, item.IceWarpAccountState); Utils.SelectListItem(ddlRespondType, item.IceWarpRespondType); chkRespondOnlyBetweenDates.Checked = item.RespondOnlyBetweenDates; // Set respond dates to something useful if they are null in IceWarp if (item.RespondFrom == DateTime.MinValue) { item.RespondFrom = DateTime.Today; } if (item.RespondTo == DateTime.MinValue) { item.RespondTo = DateTime.Today.AddDays(21); } calRespondFrom.SelectedDate = item.RespondFrom; calRespondTo.SelectedDate = item.RespondTo; chkRespondOnlyBetweenDates_CheckedChanged(this, null); txtRespondPeriodInDays.Text = item.RespondPeriodInDays.ToString(); txtRespondWithReplyFrom.Text = item.RespondWithReplyFrom; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; txtForward.Text = item.ForwardingAddresses != null ? String.Join("; ", item.ForwardingAddresses) : ""; cbDeleteOnForward.Checked = item.DeleteOnForward; cbDomainAdmin.Visible = item.IsDomainAdminEnabled; cbDomainAdmin.Checked = item.IsDomainAdmin; ddlRespondType_SelectedIndexChanged(this, null); cbForwardOlder.Checked = item.ForwardOlder; txtForwardOlderDays.Text = item.ForwardOlderDays.ToString(); txtForwardOlderTo.Text = item.ForwardOlderTo; cbForwardOlder_CheckedChanged(this, null); cbDeleteOlder.Checked = item.DeleteOlder; txtDeleteOlderDays.Text = item.DeleteOlderDays.ToString(); cbDeleteOlder_CheckedChanged(this, null); }
public void UpdateAccount(MailAccount mailbox) { Tree config = AMSHelper.GetUsersConfig(); AmsMailbox amsMailbox = new AmsMailbox(mailbox.Name); if (amsMailbox.Load(config)) { amsMailbox.LoadAccountConfig(); amsMailbox.Read(mailbox); if (!amsMailbox.Save(config)) { throw new Exception("Couldn't update specified mailbox."); } } else { throw new Exception("Couldn't find specified mailbox."); } }
public void BindItem(MailAccount item) { chkEnabled.Checked = item.Enabled; lblSizeInfo.Text = item.Size.ToString() + " MB"; lblQuotaUsedInfo.Text = item.QuotaUsed.ToString() + " %"; lblLastLoginDateInfo.Text = item.LastLogonTime; chkResponderEnabled.Checked = item.ResponderEnabled; chkResponderExpires.Checked = item.ResponderExpires; txtResponderExireDate.Text = item.ResponderExpirationDate; txtSubject.Text = item.ResponderSubject; txtMessage.Text = item.ResponderMessage; chkForwardingEnabled.Checked = item.ForwardingEnabled; txtForward.Text = item.ForwardingAddresses[0]; chkOriginalMessage.Checked = item.RetainLocalCopy; txtFirstName.Text = item.FirstName; txtLastName.Text = item.LastName; cbSignatureEnabled.Checked = item.SignatureEnabled; txtPlainSignature.Text = item.Signature; txtHtmlSignature.Text = item.SignatureHTML; secStatusInfo.IsCollapsed = false; }
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) 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); } }
public 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; mailbox.IsDomainAdminEnabled = EnableDomainAdministrators; // get additional settings string[] requestedSettings = new string[] { "isenabled", "maxsize", "lockpassword", "replytoaddress", "signature", "passwordlocked" }; 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); } }
public 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); } }
public void Read(MailAccount mailbox) { userConfig["domain"] = GetDomainName(mailbox.Name); userConfig["enabled"] = mailbox.Enabled ? "1" : "0"; userConfig["user"] = GetAccountName(mailbox.Name); userConfig["pass"] = mailbox.Password; // forwardings if (mailbox.ForwardingAddresses != null) AddForwardingInfo(mailbox.ForwardingAddresses, mailbox.DeleteOnForward); AddAutoResponderInfo(mailbox); }
public static PackageResult AddPackageWithResources(int userId, int planId, string spaceName, int statusId, bool sendLetter, bool createResources, string domainName, bool createInstantAlias, bool createWebSite, bool createFtpAccount, string ftpAccountName, bool createMailAccount) { try { TaskManager.StartTask("HOSTING_SPACE_WR", "ADD", spaceName); PackageResult result = new PackageResult(); // check account result.Result = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive | DemandAccount.IsReseller); if (result.Result < 0) return result; // check if domain exists result.Result = ServerController.CheckDomain(domainName); if (result.Result < 0) return result; // load user info UserInfo user = UserController.GetUser(userId); if (createFtpAccount) { // check if FTP account exists if (String.IsNullOrEmpty(ftpAccountName)) ftpAccountName = user.Username; if (FtpServerController.FtpAccountExists(ftpAccountName)) { result.Result = BusinessErrorCodes.ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS; return result; } } // load hosting plan HostingPlanInfo plan = PackageController.GetHostingPlan(planId); string packageName = spaceName; if (String.IsNullOrEmpty(packageName) || packageName.Trim() == "") packageName = plan.PlanName; // create package int packageId = -1; try { result = PackageController.AddPackage( userId, planId, packageName, "", statusId, DateTime.Now, false); } catch (Exception ex) { // error while adding package throw ex; } if (result.Result < 0) return result; packageId = result.Result; // create domain if (createResources) { int domainId = 0; if (!String.IsNullOrEmpty(domainName)) { try { DomainInfo domain = new DomainInfo(); domain.PackageId = packageId; domain.DomainName = domainName; domain.HostingAllowed = false; domainId = ServerController.AddDomain(domain, createInstantAlias); if (domainId < 0) { result.Result = domainId; DeletePackage(packageId); return result; } } catch (Exception ex) { // error while adding domain DeletePackage(packageId); throw new Exception("Could not add domain", ex); } } if (createWebSite && !String.IsNullOrEmpty(domainName)) { // create web site try { int webSiteId = WebServerController.AddWebSite( packageId, domainId, 0, true); if (webSiteId < 0) { result.Result = webSiteId; DeletePackage(packageId); return result; } } catch (Exception ex) { // error while creating web site DeletePackage(packageId); throw new Exception("Could not create web site", ex); } } // create FTP account if (createFtpAccount) { try { FtpAccount ftpAccount = new FtpAccount(); ftpAccount.PackageId = packageId; ftpAccount.Name = ftpAccountName; ftpAccount.Password = user.Password; ftpAccount.Folder = "\\"; ftpAccount.CanRead = true; ftpAccount.CanWrite = true; int ftpAccountId = FtpServerController.AddFtpAccount(ftpAccount); if (ftpAccountId < 0) { result.Result = ftpAccountId; DeletePackage(packageId); return result; } } catch (Exception ex) { // error while creating ftp account DeletePackage(packageId); throw new Exception("Could not create FTP account", ex); } } if (createMailAccount && !String.IsNullOrEmpty(domainName)) { // create default mailbox try { // load mail policy UserSettings settings = UserController.GetUserSettings(userId, UserSettings.MAIL_POLICY); string catchAllName = !String.IsNullOrEmpty(settings["CatchAllName"]) ? settings["CatchAllName"] : "mail"; MailAccount mailbox = new MailAccount(); mailbox.Name = catchAllName + "@" + domainName; mailbox.PackageId = packageId; // gather information from the form mailbox.Enabled = true; mailbox.ResponderEnabled = false; mailbox.ReplyTo = ""; mailbox.ResponderSubject = ""; mailbox.ResponderMessage = ""; // password mailbox.Password = user.Password; // redirection mailbox.ForwardingAddresses = new string[] { }; mailbox.DeleteOnForward = false; mailbox.MaxMailboxSize = 0; int mailAccountId = MailServerController.AddMailAccount(mailbox); if (mailAccountId < 0) { result.Result = mailAccountId; DeletePackage(packageId); return result; } // set catch-all account MailDomain mailDomain = MailServerController.GetMailDomain(packageId, domainName); mailDomain.CatchAllAccount = catchAllName; mailDomain.PostmasterAccount = "mail"; mailDomain.AbuseAccount = "mail"; MailServerController.UpdateMailDomain(mailDomain); int mailDomainId = mailDomain.Id; // set mail domain pointer // load domain instant alias string instantAlias = ServerController.GetDomainAlias(packageId, domainName); DomainInfo instantDomain = ServerController.GetDomain(instantAlias); if (instantDomain == null || instantDomain.MailDomainId > 0) instantAlias = ""; if (!String.IsNullOrEmpty(instantAlias)) MailServerController.AddMailDomainPointer(mailDomainId, instantDomain.DomainId); } catch (Exception ex) { // error while creating mail account DeletePackage(packageId); throw new Exception("Could not create mail account", ex); } } } TaskManager.ItemId = result.Result; TaskManager.TaskParameters["SendLetter"] = sendLetter; return result; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
private void SaveItem() { if (!Page.IsValid) return; // get form data MailAccount item = new MailAccount(); item.Id = PanelRequest.ItemID; item.PackageId = PanelSecurity.PackageId; item.Name = mailEditAddress.Email; item.Password = passwordControl.Password; item.MaxMailboxSize = Utils.ParseInt(txtMailBoxSizeLimit.Text); //checking if account name is different from existing e-mail lists MailList[] lists = ES.Services.MailServers.GetMailLists(PanelSecurity.PackageId, true); foreach (MailList list in lists) { if (item.Name == list.Name) { ShowWarningMessage("MAIL_ACCOUNT_NAME"); return; } } //checking if account name is different from existing e-mail groups MailGroup[] mailgroups = ES.Services.MailServers.GetMailGroups(PanelSecurity.PackageId, true); foreach (MailGroup group in mailgroups) { if (item.Name == group.Name) { ShowWarningMessage("MAIL_ACCOUNT_NAME"); return; } } //checking if account name is different from existing forwardings MailAlias[] forwardings = ES.Services.MailServers.GetMailForwardings(PanelSecurity.PackageId, true); foreach (MailAlias forwarding in forwardings) { if (item.Name == forwarding.Name) { ShowWarningMessage("MAIL_ACCOUNT_NAME"); return; } } // get other props IMailEditAccountControl ctrl = (IMailEditAccountControl)providerControl.Controls[0]; ctrl.SaveItem(item); if (PanelRequest.ItemID == 0) { // new item try { int result = ES.Services.MailServers.AddMailAccount(item); if (result < 0) { ShowResultMessage(result); return; } if (result == BusinessErrorCodes.ERROR_MAIL_LICENSE_DOMAIN_QUOTA) { ShowResultMessage(result); return; } if (result == BusinessErrorCodes.ERROR_MAIL_LICENSE_USERS_QUOTA) { ShowResultMessage(result); return; } } catch (Exception ex) { ShowErrorMessage("MAIL_ADD_ACCOUNT", ex); return; } } else { // existing item try { int result = ES.Services.MailServers.UpdateMailAccount(item); if (result < 0) { ShowResultMessage(result); return; } } catch (Exception ex) { ShowErrorMessage("MAIL_UPDATE_ACCOUNT", ex); return; } } // return RedirectSpaceHomePage(); }
public static int UpdateMailAccount(MailAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load original meta item MailAccount origItem = (MailAccount)PackageController.GetPackageItem(item.Id); if (origItem == null) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_NOT_FOUND; // check package int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // place log record TaskManager.StartTask("MAIL_ACCOUNT", "UPDATE", origItem.Name); TaskManager.ItemId = item.Id; try { // restore original props if (item.Password == "") item.Password = CryptoUtils.Decrypt(origItem.Password); // get service MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, origItem.ServiceId); item.Name = origItem.Name; item.Enabled = true; item.MaxMailboxSize = GetMaxMailBoxSize(origItem.PackageId, item); if (String.IsNullOrEmpty(item.Password)) { // get password from the service MailAccount origBox = mail.GetAccount(item.Name); item.Password = origBox.Password; } // update service item mail.UpdateAccount(item); // update meta item item.Password = CryptoUtils.Encrypt(item.Password); PackageController.UpdatePackageItem(item); return 0; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
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); } }
private static int GetMaxMailBoxSize(int packageId, MailAccount item) { // load package context int maxSize = 0; // unlimited PackageContext cntx = PackageController.GetPackageContext(packageId); if (cntx != null && cntx.Quotas.ContainsKey(Quotas.MAIL_MAXBOXSIZE)) { maxSize = cntx.Quotas[Quotas.MAIL_MAXBOXSIZE].QuotaAllocatedValue; if (maxSize == -1) return item.MaxMailboxSize; } if (maxSize == 0) { if (cntx != null && cntx.Package != null) maxSize = GetMaxMailBoxSize(cntx.Package.ParentPackageId, item); } else if (item.MaxMailboxSize != 0) { maxSize = Math.Min(item.MaxMailboxSize, maxSize); } return maxSize; }
public static int AddMailAccount(MailAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // check package int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // check quota QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.MAIL_ACCOUNTS); if (quota.QuotaExhausted) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_RESOURCE_QUOTA_LIMIT; // check if mail resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Mail); if (serviceId == 0) return BusinessErrorCodes.ERROR_MAIL_RESOURCE_UNAVAILABLE; // check package items if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(MailAccount)) != null) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_EXISTS; // place log record TaskManager.StartTask("MAIL_ACCOUNT", "ADD", item.Name); int itemId = 0; try { // check service items MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, serviceId); if (mail.AccountExists(item.Name)) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_SERVICE_ITEM_EXISTS; // add domain if not exists string domainName = item.Name.Substring(item.Name.IndexOf("@") + 1); int domainResult = AddMailDomain(item.PackageId, serviceId, domainName); if (domainResult < 0) return domainResult; // create service item item.Enabled = true; item.MaxMailboxSize = GetMaxMailBoxSize(item.PackageId, item); // add service item mail.CreateAccount(item); // save item item.Password = CryptoUtils.Encrypt(item.Password); item.ServiceId = serviceId; itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; } catch (Exception ex) { TaskManager.WriteError(ex); if (ex.InnerException != null && ex.InnerException.Message.Contains("The maximum number of domains allowed has been reached")) { return BusinessErrorCodes.ERROR_MAIL_LICENSE_DOMAIN_QUOTA; } if (ex.Message != null && ex.Message.Contains("The maximum number of users for the server has been reached")) { return BusinessErrorCodes.ERROR_MAIL_LICENSE_USERS_QUOTA; } } finally { TaskManager.CompleteTask(); } return itemId; }
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); } }
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); } }
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) 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); } }
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); } }
public MailAccount ToMailAccount() { MailAccount account = new MailAccount(); account.Name = string.Concat(userConfig["user"], "@", userConfig["domain"]); account.Enabled = userConfig["enabled"] == "1" ? true : false; account.Password = userConfig["pass"]; // read forwardings TreeNode redirection = deliveryConfig.ChildNodes["redirection"]; if (redirection != null) { TreeNode redirections = redirection.ChildNodes["redirections"]; if (redirections != null) { List<string> list = new List<string>(); foreach (TreeNode node in redirections.ChildNodes) list.Add(node.NodeValue); account.ForwardingAddresses = list.ToArray(); } } // read autoresponder TreeNode autoresponses = deliveryConfig.ChildNodes["autoresponses"]; if (autoresponses != null) { account.ResponderEnabled = autoresponses["enabled"] == "1" ? true : false; account.ResponderSubject = autoresponses["subject"]; account.ResponderMessage = autoresponses["body"]; if (autoresponses["usereplyto"] == "1") account.ReplyTo = autoresponses["replyto"]; } return account; }
private void BindItem() { try { if (!IsPostBack) { // load item if required if (PanelRequest.ItemID > 0) { // existing item try { item = ES.Services.MailServers.GetMailAccount(PanelRequest.ItemID); } catch (Exception ex) { ShowErrorMessage("MAIL_GET_ACCOUNT", ex); return; } if (item != null) { // save package info ViewState["PackageId"] = item.PackageId; mailEditAddress.PackageId = item.PackageId; passwordControl.SetPackagePolicy(item.PackageId, UserSettings.MAIL_POLICY, "AccountPasswordPolicy"); } else RedirectToBrowsePage(); } else { // new item ViewState["PackageId"] = PanelSecurity.PackageId; mailEditAddress.PackageId = PanelSecurity.PackageId; passwordControl.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.MAIL_POLICY, "AccountPasswordPolicy"); } } // load provider control LoadProviderControl((int)ViewState["PackageId"], "Mail", providerControl, "EditAccount.ascx"); // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext((int)ViewState["PackageId"]); // set messagebox size textbox visibility if (cntx.Quotas.ContainsKey(Quotas.MAIL_DISABLESIZEEDIT)) { txtMailBoxSizeLimit.Visible = cntx.Quotas[Quotas.MAIL_DISABLESIZEEDIT].QuotaAllocatedValue == 0; lblMailboxSizeLimit.Visible = txtMailBoxSizeLimit.Visible; } if (!IsPostBack) { // bind item to controls if (item != null) { // bind item to controls mailEditAddress.Email = item.Name; mailEditAddress.EditMode = true; passwordControl.EditMode = true; if (txtMailBoxSizeLimit.Visible) { txtMailBoxSizeLimit.Text = item.MaxMailboxSize.ToString(); } // other controls IMailEditAccountControl ctrl = (IMailEditAccountControl)providerControl.Controls[0]; ctrl.BindItem(item); } if (string.IsNullOrEmpty(txtMailBoxSizeLimit.Text)) { txtMailBoxSizeLimit.Text = cntx.Quotas[Quotas.MAIL_MAXBOXSIZE].QuotaAllocatedValue.ToString(); } } } catch { ShowWarningMessage("INIT_SERVICE_ITEM_FORM"); DisableFormControls(this, btnCancel); return; } }
public void UpdateAccount(MailAccount mailbox) { Tree config = AMSHelper.GetUsersConfig(); AmsMailbox amsMailbox = new AmsMailbox(mailbox.Name); if (amsMailbox.Load(config)) { amsMailbox.LoadAccountConfig(); amsMailbox.Read(mailbox); if (!amsMailbox.Save(config)) throw new Exception("Couldn't update specified mailbox."); } else { throw new Exception("Couldn't find specified mailbox."); } }