public static int UpdateMailForwarding(MailAlias item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load original meta item MailAlias origItem = (MailAlias)PackageController.GetPackageItem(item.Id); if (origItem == null) return BusinessErrorCodes.ERROR_MAIL_FORWARDINGS_PACKAGE_ITEM_NOT_FOUND; // check package int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // place log record TaskManager.StartTask("MAIL_FORWARDING", "UPDATE", origItem.Name); TaskManager.ItemId = item.Id; try { // update forwarding MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, origItem.ServiceId); MailAlias alias = new MailAlias(); alias.Name = origItem.Name; alias.ForwardTo = item.ForwardTo; //For MailEnable alias updating alias.DeleteOnForward = true; alias.ForwardingAddresses = new string[1]; alias.ForwardingAddresses[0] = item.ForwardTo; // // update service item mail.UpdateMailAlias(alias); return 0; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public int AddMailForwarding(MailAlias item) { return MailServerController.AddMailForwarding(item); }
public static int AddMailForwarding(MailAlias 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_FORWARDINGS); if (quota.QuotaExhausted) return BusinessErrorCodes.ERROR_MAIL_FORWARDINGS_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(MailAlias)) != null) return BusinessErrorCodes.ERROR_MAIL_FORWARDINGS_PACKAGE_ITEM_EXISTS; // place log record TaskManager.StartTask("MAIL_FORWARDING", "ADD", item.Name); try { // check service items MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, serviceId); if (mail.MailAliasExists(item.Name)) return BusinessErrorCodes.ERROR_MAIL_FORWARDINGS_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 MailAlias alias = new MailAlias(); alias.Name = item.Name; alias.ForwardTo = item.ForwardTo; //for MailEnable alias creation alias.DeleteOnForward = true; alias.ForwardingAddresses = new string[1]; alias.ForwardingAddresses[0] = item.ForwardTo; alias.Password = Guid.NewGuid().ToString("N").Substring(0, 12); alias.Enabled = true; // add service item mail.CreateMailAlias(alias); // save item item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; return itemId; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
private void SaveItem() { if (!Page.IsValid) return; // get form data MailAlias item = new MailAlias(); item.Id = PanelRequest.ItemID; item.PackageId = PanelSecurity.PackageId; item.Name = emailAddress.Email; item.ForwardTo = txtForwardTo.Text.Trim(); //checking if forwarding name is different from existing e-mail accounts MailAccount[] accounts = ES.Services.MailServers.GetMailAccounts(PanelSecurity.PackageId, true); foreach (MailAccount account in accounts) { if (item.Name == account.Name) { ShowWarningMessage("MAIL_FORW_NAME"); return; } } //checking if forwarding 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_FORW_NAME"); return; } } //checking if forwarding 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_FORW_NAME"); return; } } // get other props IMailEditForwardingControl ctrl = (IMailEditForwardingControl)providerControl.Controls[0]; ctrl.SaveItem(item); if (PanelRequest.ItemID == 0) { // new item try { int result = ES.Services.MailServers.AddMailForwarding(item); if (result < 0) { ShowResultMessage(result); return; } } catch (Exception ex) { ShowErrorMessage("MAIL_ADD_FORWARDING", ex); return; } } else { // existing item try { int result = ES.Services.MailServers.UpdateMailForwarding(item); if (result < 0) { ShowResultMessage(result); return; } } catch (Exception ex) { ShowErrorMessage("MAIL_UPDATE_FORWARDING", ex); return; } } // return RedirectSpaceHomePage(); }
public void BindItem(MailAlias item) { }
public MailAlias[] GetMailAliases(string domainName) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); AliasInfoListResult result = aliases.GetAliases(AdminUsername, AdminPassword, domainName); if (!result.Result) throw new Exception(result.Message); List<MailAlias> aliasesList = new List<MailAlias>(); foreach (AliasInfo alias in result.AliasInfos) { if (alias.Addresses.Length == 1) { MailAlias mailAlias = new MailAlias(); mailAlias.Name = alias.Name + "@" + domainName; mailAlias.ForwardTo = alias.Addresses[0]; aliasesList.Add(mailAlias); } } return aliasesList.ToArray(); } catch (Exception ex) { throw new Exception("Could not get the list of mail aliases", ex); } }
public void CreateMailAlias(MailAlias mailAlias) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); GenericResult result = aliases.AddAlias(AdminUsername, AdminPassword, GetDomainName(mailAlias.Name), mailAlias.Name, new string[] { mailAlias.ForwardTo }); if (!result.Result) throw new Exception(result.Message); } catch (Exception ex) { if (MailAliasExists(mailAlias.Name)) { DeleteMailAlias(mailAlias.Name); } Log.WriteError(ex); throw new Exception("Could not create mail alias", ex); } }
/// <remarks/> public void UpdateMailForwardingAsync(MailAlias item) { this.UpdateMailForwardingAsync(item, null); }
/// <remarks/> public void CreateMailAliasAsync(MailAlias mailAlias) { this.CreateMailAliasAsync(mailAlias, null); }
public int UpdateMailForwarding(MailAlias item) { object[] results = this.Invoke("UpdateMailForwarding", new object[] { item}); return ((int)(results[0])); }
/// <remarks/> public System.IAsyncResult BeginUpdateMailForwarding(MailAlias item, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("UpdateMailForwarding", new object[] { item}, callback, asyncState); }
/// <remarks/> public void AddMailForwardingAsync(MailAlias item, object userState) { if ((this.AddMailForwardingOperationCompleted == null)) { this.AddMailForwardingOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddMailForwardingOperationCompleted); } this.InvokeAsync("AddMailForwarding", new object[] { item}, this.AddMailForwardingOperationCompleted, userState); }
/// <remarks/> public void AddMailForwardingAsync(MailAlias item) { this.AddMailForwardingAsync(item, null); }
public int UpdateMailForwarding(MailAlias item) { return MailServerController.UpdateMailForwarding(item); }
public MailAlias GetMailAlias(string mailAliasName) { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); MailAlias alias = new MailAlias(); MailAlias newAlias = new MailAlias(); //convert old alliases created as mailboxes if (!MailAliasExists(mailAliasName)) { MailAccount account = GetAccount(mailAliasName); newAlias.Name = account.Name; if ((account.ForwardingAddresses != null) && (account.ForwardingAddresses.Length > 0)) { newAlias.ForwardTo = account.ForwardingAddresses[0]; } else { newAlias.ForwardTo = string.Empty; } DeleteAccount(mailAliasName); CreateMailAlias(newAlias); return newAlias; } AliasInfoResult result = aliases.GetAlias(AdminUsername, AdminPassword, GetDomainName(mailAliasName), mailAliasName); alias.Name = result.AliasInfo.Name; if ((result.AliasInfo.Addresses != null) && (result.AliasInfo.Addresses.Length > 0)) { alias.ForwardTo = result.AliasInfo.Addresses[0]; } else { alias.ForwardTo = "*****@*****.**"; } return alias; }
public void UpdateMailAlias(MailAlias mailAlias) { this.Invoke("UpdateMailAlias", new object[] { mailAlias}); }
public void UpdateMailAlias(MailAlias mailAlias) { throw new System.NotImplementedException(); }
/// <remarks/> public System.IAsyncResult BeginUpdateMailAlias(MailAlias mailAlias, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("UpdateMailAlias", new object[] { mailAlias}, callback, asyncState); }
public MailAlias GetMailAlias(string mailAliasName) { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); MailAlias alias = new MailAlias(); MailAlias newAlias = new MailAlias(); //convert old alliases created as mailboxes if (!MailAliasExists(mailAliasName)) { MailAccount account = GetAccount(mailAliasName); newAlias.Name = account.Name; newAlias.ForwardTo = account.ForwardingAddresses[0]; DeleteAccount(mailAliasName); CreateMailAlias(newAlias); return newAlias; } AliasInfoResult result = aliases.GetAlias(AdminUsername, AdminPassword, GetDomainName(mailAliasName), mailAliasName); alias.Name = result.AliasInfo.Name; alias.ForwardTo = result.AliasInfo.Addresses[0]; return alias; }
/// <remarks/> public void UpdateMailAliasAsync(MailAlias mailAlias) { this.UpdateMailAliasAsync(mailAlias, null); }
public void UpdateMailAlias(MailAlias mailAlias) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); GenericResult result = aliases.UpdateAlias(AdminUsername, AdminPassword, GetDomainName(mailAlias.Name), mailAlias.Name, new string[] { mailAlias.ForwardTo }); if (!result.Result) throw new Exception(result.Message); } catch (Exception ex) { throw new Exception("Could not update mailAlias", ex); } }
/// <remarks/> public void UpdateMailAliasAsync(MailAlias mailAlias, object userState) { if ((this.UpdateMailAliasOperationCompleted == null)) { this.UpdateMailAliasOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateMailAliasOperationCompleted); } this.InvokeAsync("UpdateMailAlias", new object[] { mailAlias}, this.UpdateMailAliasOperationCompleted, userState); }
private void BindItem() { try { if (!IsPostBack) { // load item if required if (PanelRequest.ItemID > 0) { // existing item try { item = ES.Services.MailServers.GetMailForwarding(PanelRequest.ItemID); } catch (Exception ex) { ShowErrorMessage("MAIL_GET_FORWARDING", ex); return; } if (item != null) { // save package info ViewState["PackageId"] = item.PackageId; emailAddress.PackageId = item.PackageId; } else RedirectToBrowsePage(); } else { // new item ViewState["PackageId"] = PanelSecurity.PackageId; emailAddress.PackageId = PanelSecurity.PackageId; } } // load provider control LoadProviderControl((int)ViewState["PackageId"], "Mail", providerControl, "EditForwarding.ascx"); if (!IsPostBack) { // bind item to controls if (item != null) { // bind item to controls emailAddress.Email = item.Name; emailAddress.EditMode = true; txtForwardTo.Text = item.ForwardTo; // other controls IMailEditForwardingControl ctrl = (IMailEditForwardingControl)providerControl.Controls[0]; ctrl.BindItem(item); } } } catch { ShowWarningMessage("INIT_SERVICE_ITEM_FORM"); DisableFormControls(this, btnCancel); return; } }
public int RestoreItem(string tempFolder, XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group) { if (itemType == typeof(MailDomain)) { MailServer mail = GetMailServer(serviceId); // extract meta item XmlSerializer serializer = new XmlSerializer(typeof(MailDomain)); MailDomain domain = (MailDomain)serializer.Deserialize( new XmlNodeReader(itemNode.SelectSingleNode("MailDomain"))); // create mail domain if required List<string> domains = new List<string>(); if (!mail.DomainExists(domain.Name)) { mail.CreateDomain(domain); domains.Add(domain.Name); // add domain aliases foreach (XmlNode aliasNode in itemNode.SelectNodes("Alias")) { mail.AddDomainAlias(domain.Name, aliasNode.InnerText); domains.Add(aliasNode.InnerText); } } // add meta-item if required int mailDomainId = 0; MailDomain existDomain = (MailDomain)PackageController.GetPackageItemByName(packageId, itemName, typeof(MailDomain)); if (existDomain == null) { domain.PackageId = packageId; domain.ServiceId = serviceId; mailDomainId = PackageController.AddPackageItem(domain); } else { mailDomainId = existDomain.Id; } // restore domains RestoreDomainsByMail(domains, packageId, mailDomainId); XmlSerializer accountSerializer = new XmlSerializer(typeof(MailAccount)); XmlSerializer groupSerializer = new XmlSerializer(typeof(MailGroup)); XmlSerializer listSerializer = new XmlSerializer(typeof(MailList)); // restore accounts foreach (XmlNode accountNode in itemNode.SelectNodes("MailAccount")) { MailAccount account = (MailAccount)accountSerializer.Deserialize(new XmlNodeReader(accountNode)); if (!mail.AccountExists(account.Name)) { account.Password = CryptoUtils.Decrypt(account.Password); mail.CreateAccount(account); // restore password account.Password = CryptoUtils.Encrypt(account.Password); } // add meta-item if required if (account.DeleteOnForward && PackageController.GetPackageItemByName(packageId, account.Name, typeof(MailAlias)) == null) { MailAlias forw = new MailAlias(); forw.PackageId = packageId; forw.ServiceId = serviceId; forw.Name = account.Name; PackageController.AddPackageItem(forw); } else if (!account.DeleteOnForward && PackageController.GetPackageItemByName(packageId, account.Name, typeof(MailAccount)) == null) { account.PackageId = packageId; account.ServiceId = serviceId; PackageController.AddPackageItem(account); } } // restore groups foreach (XmlNode groupNode in itemNode.SelectNodes("MailGroup")) { MailGroup mailGroup = (MailGroup)groupSerializer.Deserialize(new XmlNodeReader(groupNode)); if (!mail.GroupExists(mailGroup.Name)) { mail.CreateGroup(mailGroup); } // add meta-item if required if (PackageController.GetPackageItemByName(packageId, mailGroup.Name, typeof(MailGroup)) == null) { mailGroup.PackageId = packageId; mailGroup.ServiceId = serviceId; PackageController.AddPackageItem(mailGroup); } } // restore lists foreach (XmlNode listNode in itemNode.SelectNodes("MailList")) { MailList list = (MailList)listSerializer.Deserialize(new XmlNodeReader(listNode)); if (!mail.ListExists(list.Name)) { list.Password = CryptoUtils.Decrypt(list.Password); mail.CreateList(list); // restore password list.Password = CryptoUtils.Encrypt(list.Password); } // add meta-item if required if (PackageController.GetPackageItemByName(packageId, list.Name, typeof(MailList)) == null) { list.PackageId = packageId; list.ServiceId = serviceId; PackageController.AddPackageItem(list); } } } return 0; }
public void SaveItem(MailAlias item) { }
public void UpdateMailAlias(MailAlias mailAlias) { try { Log.WriteStart("'{0}' UpdateMailAlias", ProviderSettings.ProviderName); MailProvider.UpdateMailAlias(mailAlias); Log.WriteEnd("'{0}' UpdateMailAlias", ProviderSettings.ProviderName); } catch (Exception ex) { Log.WriteError(String.Format("'{0}' UpdateMailAlias", ProviderSettings.ProviderName), ex); throw; } }