示例#1
0
        }         // Execute

        private void UnsubscribeFromAllLists()
        {
            try {
                MCApi           mailChimpApiClient = new MCApi(ConfigManager.CurrentValues.Instance.MailChimpApiKey, true);
                MCList <string> lists = mailChimpApiClient.ListsForEmail(this.email);
                if (lists != null && lists.Any())
                {
                    foreach (var list in lists)
                    {
                        var options = new List.UnsubscribeOptions {
                            DeleteMember = true,
                            SendGoodby   = false,
                            SendNotify   = false
                        };
                        var  optOptions = new Opt <List.UnsubscribeOptions>(options);
                        bool success    = mailChimpApiClient.ListUnsubscribe(list, this.email, optOptions);
                        if (success)
                        {
                            Log.Info("{0} was unsubscribed successfully from mail chimp", this.email);
                        }
                    }
                }
            } catch (MCException mcEx) {
                Log.Warn(mcEx.Error.ToString());
            } catch (Exception ex) {
                Log.Warn(ex, "Failed unsubscribe from mail chimp email {0} for customer {1}", this.email, this.customerID);
            }
        }
        public bool UnSubscribe(string EmailAddress)

        {
            bool status = true;

            try
            {
                var mcApi = new MCApi(apiKey, false);

                var unsuboptions = new List.UnsubscribeOptions();
                unsuboptions.DeleteMember = true;
                unsuboptions.SendGoodby = false;
                unsuboptions.SendNotify = false;

                var batchUnSubscribe = mcApi.ListUnsubscribe(listId, EmailAddress, unsuboptions);
            }
            catch (Exception ex)
            {
                if (IgnoreMailchimpErrors(ex.Message))
                { }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
 public bool RemoveSubscriber(string email, string list, string apiKey, bool deleteMember = true)
 {
     var mcApi = new MCApi(apiKey, true);
     var unsubscribeOptions = new List.UnsubscribeOptions();
     unsubscribeOptions.SendGoodby = false;
     unsubscribeOptions.SendNotify = false;
     unsubscribeOptions.DeleteMember = deleteMember;
     try
     {
         return mcApi.ListUnsubscribe(list, email, unsubscribeOptions);
     }
     catch (Exception)
     {
         return false;
     }
 }