public virtual void CreateGroup(MailGroup group) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); GenericResult1 result = svcGroups.AddAlias(AdminUsername, AdminPassword, GetDomainName(group.Name), group.Name, group.Members); if (!result.Result) throw new Exception(result.Message); } catch (Exception ex) { throw new Exception("Could not create mail domain group", ex); } }
public virtual void DeleteGroup(string groupName) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); GenericResult1 result = svcGroups.DeleteAlias(AdminUsername, AdminPassword, GetDomainName(groupName), groupName); if (!result.Result) throw new Exception(result.Message); } catch (Exception ex) { throw new Exception("Could not delete mail domain group", ex); } }
public virtual MailGroup[] GetGroups(string domainName) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); AliasInfoListResult result = svcGroups.GetAliases(AdminUsername, AdminPassword, domainName); if (!result.Result) throw new Exception(result.Message); MailGroup[] groups = new MailGroup[result.AliasInfos.Length]; for (int i = 0; i < groups.Length; i++) { groups[i] = new MailGroup(); groups[i].Name = result.AliasInfos[i].Name + "@" + domainName; groups[i].Members = result.AliasInfos[i].Addresses; groups[i].Enabled = true; // by default } return groups; } catch (Exception ex) { throw new Exception("Could not get the list of mail domain groups", ex); } }
public virtual MailGroup GetGroup(string groupName) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); AliasInfoResult result = svcGroups.GetAlias(AdminUsername, AdminPassword, GetDomainName(groupName), groupName); if (!result.Result) throw new Exception(result.Message); MailGroup group = new MailGroup(); group.Name = groupName; group.Members = result.AliasInfo.Addresses; group.Enabled = true; // by default return group; } catch (Exception ex) { throw new Exception("Could not get mail domain group", ex); } }
public void DeleteMailAlias(string mailAliasName) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); GenericResult1 result = aliases.DeleteAlias(AdminUsername, AdminPassword, GetDomainName(mailAliasName), mailAliasName); if (!result.Result) throw new Exception(result.Message); } catch (Exception ex) { throw new Exception("Could not delete mailAlias", ex); } }
public virtual bool GroupExists(string groupName) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); AliasInfoResult result = svcGroups.GetAlias(AdminUsername, AdminPassword, GetDomainName(groupName), groupName); return (result.Result && result.AliasInfo.Name != "Empty"); } catch (Exception ex) { throw new Exception("Could not check whether mail domain group exists", ex); } }
public void CreateMailAlias(MailAlias mailAlias) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); GenericResult1 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); } }
public void UpdateMailAlias(MailAlias mailAlias) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); GenericResult1 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); } }
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; }
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 bool MailAliasExists(string mailAliasName) { try { svcAliasAdmin aliases = new svcAliasAdmin(); PrepareProxy(aliases); AliasInfoResult result = aliases.GetAlias(AdminUsername, AdminPassword, GetDomainName(mailAliasName), mailAliasName); if ((result.AliasInfo.Name.Equals("Empty")) && (result.AliasInfo.Addresses.Length == 0)) return false; return true; } catch (Exception ex) { throw new Exception("Could not check whether mail alias exists", ex); } }
public MailGroup[] GetGroups(string domainName) { try { svcAliasAdmin svcGroups = new svcAliasAdmin(); PrepareProxy(svcGroups); AliasInfoListResult result = svcGroups.GetAliases(AdminUsername, AdminPassword, domainName); if (!result.Result) throw new Exception(result.Message); List<MailGroup> groups = new List<MailGroup>(); foreach (AliasInfo alias in result.AliasInfos) { //group - alias with more than one forwarding address if (alias.Addresses.Length > 1) { MailGroup mailGroup = new MailGroup(); mailGroup.Name = alias.Name + "@" + domainName; mailGroup.Members = alias.Addresses; groups.Add(mailGroup); } } return groups.ToArray(); } catch (Exception ex) { throw new Exception("Could not get the list of mail domain groups", ex); } }
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; }