Пример #1
0
        public MailList GetList(string listName)
        {
            try
            {
                string domain = GetDomainName(listName);
                string account = GetAccountName(listName);

                svcMailListAdmin svcLists = new svcMailListAdmin();
                PrepareProxy(svcLists);

                SettingsRequestResult sResult = svcLists.GetRequestedListSettings(
                    AdminUsername,
                    AdminPassword,
                    domain,
                    account,
                    smListSettings
                );

                if (!sResult.Result)
                    throw new Exception(sResult.Message);

                SubscriberListResult mResult = svcLists.GetSubscriberList(
                    AdminUsername,
                    AdminPassword,
                    domain,
                    account
                );

                if (!mResult.Result)
                    throw new Exception(mResult.Message);

                MailList list = new MailList();
                list.Name = listName;

                SetMailListSettings(list, sResult.settingValues);
                SetMailListMembers(list, mResult.Subscribers);

                return list;
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't obtain mail list.", ex);
            }
        }
Пример #2
0
        public void UpdateList(MailList list)
        {
            try
            {
                string domain = GetDomainName(list.Name);
                string account = GetAccountName(list.Name);

                svcMailListAdmin lists = new svcMailListAdmin();
                PrepareProxy(lists);

                List<string> settings = new List<string>();
                settings.Add(string.Concat("description=", list.Description));
                settings.Add(string.Concat("disabled=", !list.Enabled));
                settings.Add(string.Concat("moderator=", list.ModeratorAddress));
                settings.Add(string.Concat("password="******"requirepassword="******"whocanpost=anyone");
                        break;
                    case PostingMode.MembersCanPost:
                        settings.Add("whocanpost=subscribersonly");
                        break;
                    case PostingMode.ModeratorCanPost:
                        settings.Add("whocanpost=moderator");
                        break;
                }

                settings.Add(string.Concat("prependsubject=", list.EnableSubjectPrefix));
                settings.Add(string.Concat("maxmessagesize=", list.MaxMessageSize));
                settings.Add(string.Concat("maxrecipients=", list.MaxRecipientsPerMessage));
                settings.Add(string.Concat("subject=", list.SubjectPrefix));

                switch (list.ReplyToMode)
                {
                    case ReplyTo.RepliesToList:
                        settings.Add("replytolist=true");
                        break;
                    case ReplyTo.RepliesToSender:
                        settings.Add("replytolist=false");
                        break;
                }

                settings.Add(string.Concat("listtoaddress=", list.ListToAddress));
                settings.Add(string.Concat("listfromaddress=", list.ListFromAddress));
                settings.Add(string.Concat("listreplytoaddress=", list.ListReplyToAddress));
                settings.Add(string.Concat("digestmode=", list.DigestMode));
                settings.Add(string.Concat("sendsubscribe=", list.SendSubscribe));
                settings.Add(string.Concat("sendunsubscribe=", list.SendUnsubscribe));
                settings.Add(string.Concat("allowunsubscribe=", list.AllowUnsubscribe));
                settings.Add(string.Concat("disablelistcommand=", list.DisableListcommand));
                settings.Add(string.Concat("disablesubscribecommand=", list.DisableSubscribecommand));

                GenericResult result = lists.SetRequestedListSettings(AdminUsername, AdminPassword,
                                                                      domain,
                                                                      account,
                                                                      settings.ToArray()
                    );

                if (!result.Result)
                    throw new Exception(result.Message);

                 SubscriberListResult subsribersResult = lists.GetSubscriberList(AdminUsername, AdminPassword, domain, account);

                foreach (string member in subsribersResult.Subscribers)
                {
                    GenericResult memberResult = lists.RemoveSubscriber(AdminUsername, AdminPassword, domain, account, member);
                    if (!memberResult.Result)
                    {
                        throw new Exception(memberResult.Message);
                    }

                }


                    //if (list.Members.Length > 0)
                    //{
                    result = lists.SetSubscriberList(AdminUsername, AdminPassword,
                                                     domain,
                                                     account,
                                                     list.Members
                        );

                    if (!result.Result)
                        throw new Exception(result.Message);
                    //}
                }
            catch (Exception ex)
                {
                    throw new Exception("Couldn't update mail list.", ex);
                }
          
        }
Пример #3
0
        public MailList[] GetLists(string domainName)
        {
            try
            {
                svcMailListAdmin svcLists = new svcMailListAdmin();
                PrepareProxy(svcLists);

                MailingListResult mResult = svcLists.GetMailingListsByDomain(
                    AdminUsername,
                    AdminPassword,
                    domainName
                );

                if (!mResult.Result)
                    throw new Exception(mResult.Message);

                List<MailList> mailLists = new List<MailList>();
                foreach (string listName in mResult.listNames)
                {
                    SettingsRequestResult sResult = svcLists.GetRequestedListSettings(
                        AdminUsername,
                        AdminPassword,
                        domainName,
                        listName,
                        smListSettings
                    );

                    if (!sResult.Result)
                        throw new Exception(sResult.Message);

                    SubscriberListResult rResult = svcLists.GetSubscriberList(
                        AdminUsername,
                        AdminPassword,
                        domainName,
                        listName
                    );

                    if (!rResult.Result)
                        throw new Exception(rResult.Message);

                    MailList list = new MailList();
                    list.Name = string.Concat(listName, "@", domainName);
                    SetMailListSettings(list, sResult.settingValues);
                    SetMailListMembers(list, rResult.Subscribers);
                    mailLists.Add(list);
                }

                return mailLists.ToArray();
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't obtain domain mail lists.", ex);
            }
        }