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;
        }
示例#2
0
        protected void AddEmailToMailChimp(string email, string firstName, string lastName, string listId)
        {
            string apiKey = ConfigurationManager.AppSettings["MailChimpApiKey"];


            var options = new List.SubscribeOptions();

            options.DoubleOptIn = true;
            options.EmailType   = List.EmailType.Html;
            options.SendWelcome = true;

            var mergeText = new List.Merges(email, List.EmailType.Text)
            {
                { "FNAME", firstName },
                { "LNAME", lastName }
            };
            var merges = new List <List.Merges> {
                mergeText
            };

            var mcApi          = new MCApi(apiKey, false);
            var batchSubscribe = mcApi.ListBatchSubscribe(listId, merges, options);

            if (batchSubscribe.Errors.Count > 0)
            {
                _logger.Error(batchSubscribe.Errors[0].Message, null);
            }
        }
        //Footer Signup 
        public bool Subscribe_SingleSignUp(string EmailAddress)
        {
            bool status = true;

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

                List<List.Merges> SubscriptionInfo = new List<List.Merges>();

                var SubscriptionOptions = new MailChimp.Types.List.SubscribeOptions();
                SubscriptionOptions.DoubleOptIn = false;
                SubscriptionOptions.ReplaceInterests = false;
                SubscriptionOptions.EmailType = List.EmailType.Html;
                SubscriptionOptions.SendWelcome = false;
                SubscriptionOptions.UpdateExisting = true;

                var merges = GetListOfMerges_SingleSignUp(EmailAddress);

                var returnvalue = mcApi.ListSubscribe(MANvFATOfficialMembers_ListId, EmailAddress, merges, SubscriptionOptions);
            }
            catch (Exception ex)
            {
                if (IgnoreMailchimpErrors(ex.Message))
                { }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
        public ActionResult Subscribe(MailingListSubscribeViewModel viewModel)
        {
            //TODO: Remove this as it is for fake processing to check that only ".com" addresses are valid
            if (!ModelState.IsValid)
            {
                //TODO: move to base class and need to pull in my tempdata cookieprovider so we are multi-server tolerant with tempdata
                TempData["ViewData"] = ViewData;
                return(RedirectToAction("Subscribe"));
            }

            //TODO: do actual subscription processing

            string mailChimpApiKey = ConfigurationSettings.AppSettings["MailChimpApiKey"];
            string mailChimpListId = ConfigurationSettings.AppSettings["MailChimpListId"];

            var mailChimp = new MCApi(mailChimpApiKey, true);

            mailChimp.ListSubscribe(mailChimpListId, viewModel.EmailAddress,
                                    new List.Merges {
                { "FNAME", viewModel.FirstName },
                { "LNAME", viewModel.LastName }
            }, new List.SubscribeOptions()
            {
                DoubleOptIn    = false,
                SendWelcome    = false,
                UpdateExisting = true
            });

            //TODO: move to base class and need to pull in my tempdata cookieprovider so we are multi-server tolerant with tempdata
            TempData["alert-success"] = "Thank you! You are now signed up.";
            return(RedirectToAction("Subscribe"));
        }
示例#5
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 ActionResult Subscribe(MailingListSubscribeViewModel viewModel)
        {
            //TODO: Remove this as it is for fake processing to check that only ".com" addresses are valid
            if (!ModelState.IsValid) {
                //TODO: move to base class and need to pull in my tempdata cookieprovider so we are multi-server tolerant with tempdata
                TempData["ViewData"] = ViewData;
                return RedirectToAction("Subscribe");
            }

            //TODO: do actual subscription processing

            string mailChimpApiKey = ConfigurationSettings.AppSettings["MailChimpApiKey"];
            string mailChimpListId = ConfigurationSettings.AppSettings["MailChimpListId"];

            var mailChimp = new MCApi(mailChimpApiKey, true);

            mailChimp.ListSubscribe(mailChimpListId, viewModel.EmailAddress,
                                    new List.Merges {
                                        {"FNAME", viewModel.FirstName},
                                        {"LNAME", viewModel.LastName}
                                    }, new List.SubscribeOptions() {
                                        DoubleOptIn = false,
                                        SendWelcome = false,
                                        UpdateExisting = true
                                    });

            //TODO: move to base class and need to pull in my tempdata cookieprovider so we are multi-server tolerant with tempdata
            TempData["alert-success"] = "Thank you! You are now signed up.";
            return RedirectToAction("Subscribe");
        }
        public bool UpdateSubscriber(PlayersExt model)
        {
            bool status = true;

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

                var returnval = mcApi.ListUpdateMember(listId, model.EmailAddress, merges, List.EmailType.Html, true);
            }
            catch (Exception ex)
            {
                //If try to update and didn't found any record so it means it is not already Subscribed.
                //in this case Subscribe the player
                if (IgnoreMailchimpErrors(ex.Message))
                {
                    status = Subscribe(model);
                }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
示例#8
0
 public MailChimp()
 {
     var config = MailChimpConfiguration.Load();
     _configApiKey = config.APIKey;
     _listName = config.ListName;
     _retryCount = config.RetryCount;
     _listColumns = config.ListColumns;
     _wrapper = new MCApi(_configApiKey, true);
 }
示例#9
0
        public Dictionary <string, string> SubscribeBatch(DataTable subscribers)
        {
            var mc = new MCApi(_apiKey, true);
            var subscribeOptions =
                new List.SubscribeOptions
            {
                DoubleOptIn    = false,
                SendWelcome    = true,
                UpdateExisting = true,
            };

            var merges = new List <List.Merges>();

            Dictionary <int, string> fields = GetFieldsName(subscribers);

            try
            {
                subscribers.Columns["EMAIL"].AllowDBNull = false;
            }
            catch (Exception ex)
            {
                throw new DuradosException("Email is missing", ex);
            }
            try
            {
                subscribers.PrimaryKey = new DataColumn[] { subscribers.Columns["EMAIL"] };
            }
            catch (Exception ex)
            {
                throw new DuradosException("Email must be unique", ex);
            }


            foreach (DataRow row in subscribers.Rows)
            {
                var merge = new List.Merges();

                for (int i = 0; i < subscribers.Columns.Count; i++)
                {
                    string val = row[i].ToString();
                    if (subscribers.Columns[i].DataType == typeof(bool))
                    {
                        val = Convert.ToInt32(row.IsNull(i) ? false : row[i]).ToString();
                    }
                    merge.Add(fields[i], val);
                }
                merges.Add(merge);
            }
            if (merges.Count == 0)
            {
                return(null);
            }
            List.BatchSubscribe lbs = mc.ListBatchSubscribe(_listId, merges, subscribeOptions);

            return(GetErrors(subscribers, lbs));
        }
 public bool UpdateSubscriberEmail(string oldEmail, string newEmail, string apiKey)
 {
     var mcApi = new MCApi(apiKey, true);
     var merges = new List.Merges();
     var subscriptionOptions = new List.SubscribeOptions();
     subscriptionOptions.UpdateExisting = true;
     subscriptionOptions.DoubleOptIn = false;
     subscriptionOptions.SendWelcome = false;
     return mcApi.ListUpdateMember().ListSubscribe(list, email, merges, subscriptionOptions);
 }
示例#11
0
        public MailChimpApiControler(AConnection oDB, ASafeLog oLog)
        {
            string sApikey = System.Configuration.ConfigurationManager.AppSettings["apikey"];

            m_oMcApi = new MCApi(sApikey, true);

            ms_oDB  = oDB;
            ms_oLog = new SafeLog(oLog);

            DbCmd = new DbCommands(ms_oDB, ms_oLog);
        }         // Init
示例#12
0
        public static void AccedeApi(string nombre, string apPaterno, string correo)
        {
            const string apiKey  = "eef4bc1722806a84538bc67d058b44c0-us7"; // Replace it before
            string       listId  = "c9ad222383";                           // Replace it before
            string       listId1 = "e321ec7f9d";

            var options = new List.SubscribeOptions
            {
                DoubleOptIn = true, EmailType = List.EmailType.Html, SendWelcome = false
            };

            //var entry = new Dictionary<string, object>();
            //entry.Add("FNAME", "Sergio");
            //entry.Add("LNAME", "Alvarez");

            //var lsi =  new listSubscribe(apiKey, listId, "*****@*****.**", entry);


            var mergeText = new List.Merges()
            {
                { "FNAME", nombre },
                { "LNAME", apPaterno }
            };
            //var merges = new List<List.Merges> { mergeText };

            var mcApi = new MCApi(apiKey, false);


            mcApi.ListSubscribe(listId, correo, mergeText, options);
            //mcApi.ListMergeVarAdd(listId, "Test", "Testing");


            //var lstMailChimp = mcApi.ListClients("e321ec7f9d");
            //mcApi.ListMembers("e321ec7f9d", List.MemberStatus.Subscribed).Data[1];
            //mcApi.ListSubscribe(listId, "*****@*****.**");

            //var listaClientes = mcApi.ListMembers(listId, List.MemberStatus.Subscribed).Data;
            //var lstMember = mcApi.ListMergeVars(listId);

            //foreach (var item in listaClientes)
            //{
            //    var email = item.Email;
            //    var description = item.Description;
            //    var reason = item.Reason;
            //    var timestamp = item.Timestamp;
            //}

            //foreach (var mergeVar in lstMember)
            //{
            //    var name = mergeVar.Name;
            //    var ejemplo = mergeVar.HelpText[0];
            //}
        }
        public EmailSubscriptionsOperationStatus GetSubscriptions(string email)
        {
            var operationStatus = new EmailSubscriptionsOperationStatus();
            try
            {

                MCApi api = new MCApi(_apiKey, false);
                var subscriptions = new EmailSubscriptions();
                subscriptions.Email = email;
                var testResults = api.ListMemberInfo(_listId, email);
                if (testResults.Success.Value == 1)
                {
                    var merges = testResults.Data[0].Merges;

                    foreach (var merge in merges)
                    {
                        if (merge.Key == "GROUPINGS")
                        {
                            var grouping = (List.Grouping[]) merge.Value;
                            if (grouping.Count() > 0)
                                subscriptions.Subscriptions = grouping[0].Groups.ToList();
                            operationStatus.Status = true;
                            operationStatus.SubscriptionStatus = true;
                        }
                        if (merge.Key == "FNAME")
                        {
                            subscriptions.ForeName = merge.Value.ToString();
                        }
                        if (merge.Key == "LNAME")
                        {
                            subscriptions.LastName = merge.Value.ToString();
                        }
                    }
                    operationStatus.SubscriptionStatus = true;
                }
                else
                {
                    operationStatus.SubscriptionStatus = false;
                    operationStatus.Message = testResults.ErrorsData[0].ToString();
                }
                operationStatus.Status = true;
                operationStatus.EmailSubscriptions = subscriptions;
            }
            catch (Exception e)
            {
                operationStatus = OperationStatusExceptionHelper<EmailSubscriptionsOperationStatus>
                    .CreateFromException("An error has occurred while retrieving the email subscriptions", e);

            }
            return operationStatus;
        }
示例#14
0
        public static bool signup(string email, string firstName = null, string lastname = null)
        {
            if (email!=null)
            {
                MCApi mc = new MCApi(apiKey, true);

                if (mc.ListSubscribe("7c72db4561", email))
                {
                    return true;
                }
            }

            return false;
        }
 public bool AddOrUpdateSubscriber(string email, string list, string apiKey, string firstName, string lastName, string title, string company, string guid)
 {
     var mcApi = new MCApi(apiKey, true);
     var merges = new List.Merges();
     merges.Add("FNAME", firstName);
     merges.Add("LNAME", lastName);
     merges.Add("TITLE", title);
     merges.Add("COMPANY", company);
     merges.Add("GUID", guid);
     var subscriptionOptions = new List.SubscribeOptions();
     subscriptionOptions.UpdateExisting = true;
     subscriptionOptions.DoubleOptIn = false;
     subscriptionOptions.SendWelcome = false;
     return mcApi.ListSubscribe(list, email, merges, subscriptionOptions);
 }
示例#16
0
		public bool AddToMailingList(string firstName, string lastName, string email, int list = 0)
		{
			MCApi server = new MCApi(mailingListToken, false);
			List.Merges merge_vars = new List.Merges();
			merge_vars.Add("fName", firstName);
			merge_vars.Add("lName", lastName);
			string mailChimpList;
			switch (list)
			{
				case 1: mailChimpList = mailChimpGeneralList; break;
				default: mailChimpList = mailChimpIBOList; break;
			}
			server.ListSubscribe(mailChimpIBOList, email, merge_vars);
			return false;
		}
 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;
     }
 }
示例#18
0
        protected void btnSuscribir_Click(object sender, EventArgs e)
        {
            String resultado = "";

            try
            {
                const string apiKey = "a3bcf72bb39572c06e9d2a3747cd8eaa-us3"; // Replace it before
                const string listId = "41afc6c854";                           // Replace it before

                var options = new List.SubscribeOptions();
                options.DoubleOptIn = true;
                options.EmailType   = List.EmailType.Html;
                options.SendWelcome = false;

                var mergeText = new List.Merges(txtSuscribir.Text, List.EmailType.Text);
                var merges    = new List <List.Merges> {
                    mergeText
                };

                var mcApi          = new MCApi(apiKey, false);
                var batchSubscribe = mcApi.ListBatchSubscribe(listId, merges, options);


                if (batchSubscribe.Errors.Count > 0)
                {
                    resultado = "?ress=error";
                    System.Diagnostics.Debug.WriteLine("Error:{0}", batchSubscribe.Errors[0].Message);
                }
                else
                {
                    resultado = "?ress=succ";
                    System.Diagnostics.Debug.WriteLine("Success");
                }
            }
            catch (MailChimp.Types.MCException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                Response.Redirect("Default.aspx" + resultado);
            }
        }
 public bool SendCampaign(string url, string urlParams, string fromEmail, string fromName, string list, string emailSubject, string camapaignTitle, List<string> emails, string apiKey)
 {
     var mcApi = new MCApi(apiKey, true);
     var options = new Campaign.Options(list, camapaignTitle, fromEmail, fromName, fromName); 
     var content = new Campaign.Content.Html();
   
     var guid = Guid.NewGuid();
     var segmentName = "qi_" + guid;
     
     var segmentId = 0;
     if(segmentId == 0) segmentId = mcApi.ListStaticSegmentAdd(list, segmentName);
     mcApi.ListStaticSegmentMembersAdd(list, segmentId, emails);
     var segmentIds =  new List<string>();
     segmentIds.Add(segmentId.ToString());
     var condition = new Campaign.SegmentCondition("static_segment", "eq", segmentIds);
     var conditions = new MCList<Campaign.SegmentCondition>();
     conditions.Add(condition);
     var segmentOptions = new Campaign.SegmentOptions(Campaign.Match.AND, conditions);
     content.Url = url;
     
     var success = false;
     LogManager.GetLogger(GetType().FullName + " " + camapaignTitle).Info("Test de campagne" + " / Nb emails : " + emails.Count + " / Url : " + url);
     try
     {
         var id = mcApi.CampaignCreate(Campaign.Type.Regular, options, content, segmentOptions);
         LogManager.GetLogger(GetType().FullName + " " + camapaignTitle).Info("Création de campagne - " + id);
         try
         {
             success = !string.IsNullOrEmpty(id) && mcApi.CampaignSendNow(id);
             LogManager.GetLogger(GetType().FullName + " " + camapaignTitle).Info("Envoi de campagne - " + id + " Statut : " + success + " / Nb emails : " + emails.Count + " / Url : " + url);
             return success;
         }
         catch (Exception ex)
         {
             LogManager.GetLogger(GetType().FullName + " " + camapaignTitle).Fatal(string.Format("Erreur lors de l'envoi d'une campagne {0} {1}", ex.Message, ex.StackTrace));
         }
     }
     catch(Exception ex)
     {
         LogManager.GetLogger(GetType().FullName + " " + camapaignTitle).Fatal(string.Format("Erreur lors de la création d'une campagne {0} {1}", ex.Message, ex.StackTrace));
     }
     return success;
 }
        public bool Subscribe_NonPaidPlayers(PlayersExt model)
        {
            bool status = true;

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

                //var lists = mcApi.Lists();

                //foreach (var item in lists.Data)
                //{
                //    string listID = item.ListID;
                //}

                List<List.Merges> SubscriptionInfo = new List<List.Merges>();

                var SubscriptionOptions = new MailChimp.Types.List.SubscribeOptions();
                SubscriptionOptions.DoubleOptIn = false;
                SubscriptionOptions.ReplaceInterests = false;
                SubscriptionOptions.EmailType = List.EmailType.Html;
                SubscriptionOptions.SendWelcome = false;
                SubscriptionOptions.UpdateExisting = true;

                var merges = GetListOfMerges(model);

                var returnvalue = mcApi.ListSubscribe(NonPaidPlayers_ListId, model.EmailAddress, merges, SubscriptionOptions);
            }
            catch (Exception ex)
            {
                if (IgnoreMailchimpErrors(ex.Message))
                { }
                else
                {
                    ErrorHandling.HandleException(ex);
                    status = false;
                }
            }

            return status;
        }
示例#21
0
        public static bool testUserSignup(string email, string firstName, string lastName, string phone, string companyName, string cvr)
        {
            if (email != null && firstName != null && lastName != null && phone != null && companyName != null && cvr != null)
            {
                MCApi mc = new MCApi(apiKey, true);

                List.Merges merges = new List.Merges();
                merges.Add("FNAME", firstName);
                merges.Add("LNAME", lastName);
                merges.Add("CNAME", companyName);
                merges.Add("CVR", cvr);
                merges.Add("PHONE", phone);

                if (mc.ListSubscribe("908bfd3981", email, merges))
                {
                    return true;
                }
            }

            return false;
        }
示例#22
0
        public static bool MailChimpUnSubscribe(List <string> emails, string ListId)
        {
            try
            {
                var mc = new MCApi(ConfigurationManager.AppSettings["MailChimpAPIKey"], true);

                var UnsubscribeOptions =
                    new Opt <List.UnsubscribeOptions>(
                        new List.UnsubscribeOptions
                {
                    DeleteMember = true,
                    SendGoodby   = false,
                    SendNotify   = false
                });
                mc.ListBatchUnsubscribe(ListId, emails, UnsubscribeOptions);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#23
0
        public MailChimp(
            string apiKey,
            string listName,
            int retryCount,
            IEnumerable<MailChimpColumn> listColumns)
        {
            _configApiKey = apiKey;
            _wrapper = new MCApi(_configApiKey, true);
            _listName = listName;
            _retryCount = retryCount;
            _listColumns = new List<MCMergeVar>();

            foreach (var column in listColumns)
            {
                _listColumns.Add(new MCMergeVar
                {
                    name = column.Name,
                    req = column.Required,
                    tag = column.Tag
                });
            }

            GetMailChimpListMembers();
        }
示例#24
0
        /// <summary>
        /// This function will add user to Mailchimp Subscription List
        /// </summary>
        /// <param name="emailId">EmailId of the user</param>
        /// <param name="firstName">First Name of the user</param>
        /// <param name="LastName">Last Name of the User</param>
        /// <param name="isSubscribeOnly">Checks if this is only subscribtion . while registering we'll add user to list , but we'll send subscription mail to user..in that case it'll be false.</param>
        /// <returns></returns>
        public string SaveToMailChimpList(string emailId, string firstName, string LastName,bool isSubscribeOnly)
        {
            MCApi api = new MCApi(ConfigurationManager.AppSettings["MailChimpApiKey"], false);

            List.Filter lf = new List.Filter();
            lf.ListName = ConfigurationManager.AppSettings["MailChimpListName"];
            List.Lists lists = api.Lists(lf);

            if (lists.Total > 0)
            {
                string listId = lists.Data[0].ListID;

                List.SubscribeOptions so = new List.SubscribeOptions();
                so.DoubleOptIn = false;

                List.Merges merges = new List.Merges();
                merges.Add("FNAME", firstName);
                merges.Add("LNAME", LastName);
                var uservailble = api.ListMemberInfo(listId, emailId);
                if (uservailble.Data[0].Email==null)
                {
                    if (api.ListSubscribe(listId, emailId, merges, so))
                    {
                        //send mail to user
                        if (isSubscribeOnly)
                        {
                            //send emailid in place of mail because name is empty in this case.
                            NotifyUser(emailId, emailId, "Thanks for showing interest in LockYourStay!", "Thank you for subscribing Lockyourstay.We will keep you posted with all updates.", "Notify User");
                        }
                        return "Thank you for your subscription!";
                    }
                    else
                    {
                        return "Something went wrong! Please try again later.";
                    }
                }
                else
                {
                    return "Email already exists!";
                }
            }
            else
            {
                //no list available
                return "Something went wrong! Please try again later.";
            }
        }
        public EmailSubscriptionsOperationStatus SynchroniseSubscriptions(EmailSubscriptions subscriptions)
        {
            var operationStatus = new EmailSubscriptionsOperationStatus();
            try
            {
                MCApi api = new MCApi(_apiKey, false);
                var subscribeOptions =
                    new Opt<List.SubscribeOptions>(
                        new List.SubscribeOptions
                        {
                            SendWelcome = true,
                            UpdateExisting = true,
                            DoubleOptIn = (subscriptions.Subscriptions.Count() != 0),
                            //retain double optin for new subscribers
                            ReplaceInterests = true
                        });

                var groupings = new List<List.Grouping>()
                {
                    new List.Grouping("Signed Up As", subscriptions.Subscriptions.ToArray()),
                };

                var merges =
                    new Opt<List.Merges>(
                        new List.Merges
                        {
                            {"FNAME", subscriptions.ForeName},
                            {"LNAME", subscriptions.LastName},
                            {"GROUPINGS", groupings}
                        });

                operationStatus.Status = api.ListSubscribe(_listId, subscriptions.Email, merges, subscribeOptions);
                operationStatus.SubscriptionStatus = true;
            }
            catch (Exception e)
            {
                operationStatus = OperationStatusExceptionHelper<EmailSubscriptionsOperationStatus>
                    .CreateFromException("An error has occurred while syncing the email subscriptions", e);
                operationStatus.SubscriptionStatus = false;

            }
            return operationStatus;
        }
示例#26
0
        public static bool AddMailChimpSubscriber(string email, string username, bool updateExisting, bool sendWelcome)
        {
            try
            {
                var mc = new MCApi(ConfigurationManager.AppSettings["MailChimpAPIKey"], true);

                var subscribedId   = ConfigurationManager.AppSettings["MailChimpSubscribedUsersListId"];
                var unsubscribedId = ConfigurationManager.AppSettings["MailChimpUnSubscribedUserListId"];
                if (updateExisting)
                {
                    var User = mc.ListMemberInfo(unsubscribedId, new List <string> {
                        email
                    });
                    if (User.Success.Value > 0)
                    {
                        MailChimpUnSubscribe(new List <string> {
                            email
                        }, unsubscribedId);
                    }
                }
                else
                {
                    var User = mc.ListMemberInfo(unsubscribedId, new List <string> {
                        email
                    });
                    if (User.Success.Value == 0)
                    {
                        var SubUser = mc.ListMemberInfo(subscribedId, new List <string> {
                            email
                        });
                        if (SubUser.Success.Value > 0)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                var subscribeOptions =
                    new Opt <List.SubscribeOptions>(
                        new List.SubscribeOptions
                {
                    DoubleOptIn    = false,
                    SendWelcome    = sendWelcome,
                    UpdateExisting = updateExisting,
                });
                var merges = new Opt <List.Merges>(
                    new List.Merges
                {
                    { "FNAME", username },
                });
                return(mc.ListSubscribe(updateExisting ? subscribedId : unsubscribedId, email, merges, subscribeOptions));
            }
            catch
            {
                return(false);
            }
        }
示例#27
0
        protected  void AddEmailToMailChimp(string email, string firstName, string lastName, string listId)
        {
            string apiKey = ConfigurationManager.AppSettings["MailChimpApiKey"];
            

            var options = new List.SubscribeOptions();
            options.DoubleOptIn = true;
            options.EmailType = List.EmailType.Html;
            options.SendWelcome = true;

            var mergeText = new List.Merges(email, List.EmailType.Text)
                    {
                        {"FNAME", firstName},
                        {"LNAME", lastName}
                    };
            var merges = new List<List.Merges> { mergeText };

            var mcApi = new MCApi(apiKey, false);
            var batchSubscribe = mcApi.ListBatchSubscribe(listId, merges, options);

            if (batchSubscribe.Errors.Count > 0)
            {
                _logger.Error(batchSubscribe.Errors[0].Message, null);
            }
        }