public virtual MailAccount GetAccount(string mailboxName) { try { svcUserAdmin users = new svcUserAdmin(); PrepareProxy(users); UserInfoResult result = users.GetUser(AdminUsername, AdminPassword, mailboxName); if (!result.Result) throw new Exception(result.Message); MailAccount mailbox = new MailAccount(); mailbox.Name = result.UserInfo.UserName; mailbox.Password = result.UserInfo.Password; mailbox.FirstName = result.UserInfo.FirstName; mailbox.LastName = result.UserInfo.LastName; mailbox.IsDomainAdmin = result.UserInfo.IsDomainAdmin; // get additional settings string[] requestedSettings = new string[] { "isenabled", "maxsize", "passwordlocked", "replytoaddress", "signature" }; SettingsRequestResult addResult = users.GetRequestedUserSettings(AdminUsername, AdminPassword, mailboxName, requestedSettings); if (!addResult.Result) throw new Exception(addResult.Message); foreach (string pair in addResult.settingValues) { string[] parts = pair.Split('='); if (parts[0] == "isenabled") mailbox.Enabled = Boolean.Parse(parts[1]); else if (parts[0] == "maxsize") mailbox.MaxMailboxSize = Int32.Parse(parts[1]); else if (parts[0] == "passwordlocked") mailbox.PasswordLocked = Boolean.Parse(parts[1]); else if (parts[0] == "replytoaddress") mailbox.ReplyTo = parts[1]; else if (parts[0] == "signature") mailbox.Signature = parts[1]; } // get forwardings info UserForwardingInfoResult forwResult = users.GetUserForwardingInfo(AdminUsername, AdminPassword, mailboxName); if (!forwResult.Result) throw new Exception(forwResult.Message); string[] forwAddresses = forwResult.ForwardingAddress.Split(';', ','); List<string> listForAddresses = new List<string>(); foreach (string forwAddress in forwAddresses) { if (!String.IsNullOrEmpty(forwAddress.Trim())) listForAddresses.Add(forwAddress.Trim()); } mailbox.ForwardingAddresses = listForAddresses.ToArray(); mailbox.DeleteOnForward = forwResult.DeleteOnForward; // get autoresponder info UserAutoResponseResult respResult = users.GetUserAutoResponseInfo(AdminUsername, AdminPassword, mailboxName); if (!respResult.Result) throw new Exception(respResult.Message); mailbox.ResponderEnabled = respResult.Enabled; mailbox.ResponderSubject = respResult.Subject; mailbox.ResponderMessage = respResult.Body; return mailbox; } catch (Exception ex) { throw new Exception("Could not get mailbox", ex); } }
public virtual bool AccountExists(string mailboxName) { try { svcUserAdmin users = new svcUserAdmin(); PrepareProxy(users); UserInfoResult result = users.GetUser(AdminUsername, AdminPassword, mailboxName); return result.Result; } catch (Exception ex) { throw new Exception("Could not check whether mailbox exists", ex); } }