示例#1
0
        /*
         * Copy Of Dealers Invited To My.Paoli.Com (Dev-Test)
         * Dealer List (Test)
         * Sales Rep List (Test)
         */
        private static void AddEmailAddress(string emailAddress, string listConfig, Dictionary <string, string> map)
        {
            var lists = ConfigurationManager.AppSettings[listConfig].ToString();

            if (string.IsNullOrEmpty(lists))
            {
                return;
            }

            try
            {
                MailChimpManager mc = new MailChimpManager(ConfigurationManager.AppSettings["MailChimpApiKey"]);

                //  Create the email parameter
                EmailParameter email = new EmailParameter()
                {
                    Email = emailAddress
                };

                var details = new MergeVar();
                foreach (var item in map)
                {
                    details.Add(item.Key, item.Value);
                }

                foreach (var listId in lists.Split(',').Select(s => s.Trim()))
                {
                    EmailParameter results = mc.Subscribe(listId, email, doubleOptIn: false, mergeVars: details);
                }
            }
            catch
            {
            }
        }
示例#2
0
        internal static Subscriber Build(
            string email,
            string status,
            MergeVar mergeVar)
        {
            ExceptionHandler.HandleEmptyStringArgument(email, "Email cannot be null.");
            ExceptionHandler.HandleEmptyStringArgument(status, "Status cannot be null.");
            ExceptionHandler.HandleNullArgument(mergeVar, "MergeVar cannot be null.");

            return(new Subscriber(email, status, mergeVar));
        }
示例#3
0
        public void BatchSubscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();

            List <BatchEmailParameter> emails = new List <BatchEmailParameter>();

            BatchEmailParameter email1 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
            MergeVar mVar1 = new MergeVar();

            mVar1.Add("FNAME", "first1" + DateTime.Now);
            mVar1.Add("LNAME", "last1" + DateTime.Now);
            email1.MergeVars = mVar1;
            emails.Add(email1);

            BatchEmailParameter email2 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
            MergeVar mVar2 = new MergeVar();

            mVar2.Add("FNAME", "first2" + DateTime.Now);
            mVar2.Add("LNAME", "last2" + DateTime.Now);
            email2.MergeVars = mVar2;
            emails.Add(email2);

            //  Act
            BatchSubscribeResult results = mc.BatchSubscribe(lists.Data[0].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.AddCount == 2);

            // load
            List <EmailParameter> emailsP = new List <EmailParameter>();

            emailsP.Add(email1.Email);
            MemberInfoResult memberInfo = mc.GetMemberInfo(lists.Data[0].Id, emailsP);

            Assert.AreEqual(mVar1["FNAME"], memberInfo.Data[0].MemberMergeInfo["FNAME"]);
            Assert.AreEqual(mVar1["LNAME"], memberInfo.Data[0].MemberMergeInfo["LNAME"]);
        }
示例#4
0
    public static void SubscribeUserToMailChimp(string emailId, string userName)
    {
        string apiKey = ConfigurationManager.AppSettings["MailchimpAPIKey"];

        MailChimp.Lists.MergeVar myMergeVars = new MergeVar();
        myMergeVars.Add("FNAME", userName);
        //myMergeVars.Add("LNAME", "Testerson");

        MailChimpManager mc = new MailChimpManager(apiKey);

        //  Create the email parameter
        EmailParameter email = new EmailParameter()
        {
            Email = emailId
        };

        EmailParameter results = mc.Subscribe("5bea4adf5a", email, myMergeVars, "html", false, true, true, false);
    }
示例#5
0
        public ActionResult Index(Newsletter mailAddress)
        {
            var mergedVariables = new MergeVar();

            mergedVariables.Add("FNAME", "KULLANICI ADI");
            mergedVariables.Add("LNAME", "KULLANICI SOYADI");

            var mc = new MailChimpManager("api key is here");

            var email = new EmailParameter()
            {
                Email = mailAddress.email
            };

            var result = mc.Subscribe("list id is here", email, mergedVariables, doubleOptIn: false, updateExisting: true);

            ViewBag.Success = true;

            return(View());
        }
示例#6
0
        /// <summary>
        /// Subscribe the provided email to a list. By default this sends a
        /// confirmation email - you will not see new members until the
        /// link contained in it is clicked!
        /// </summary>
        /// <param name="listId">the list id to connect to (can be gathered using GetLists())</param>
        /// <param name="emailParam">An object a with one fo the following keys: email, euid, leid. Failing to provide anything will produce an error relating to the email address</param>
        /// <param name="mergeVars">optional merges for the email (FNAME, LNAME, etc.)</param>
        /// <param name="emailType">optional email type preference for the email (html or text - defaults to html)</param>
        /// <param name="doubleOptIn">optional flag to control whether a double opt-in confirmation message is sent, defaults to true. Abusing this may cause your account to be suspended.</param>
        /// <param name="updateExisting">optional flag to control whether existing subscribers should be updated instead of throwing an error, defaults to false</param>
        /// <param name="replaceInterests">optional flag to determine whether we replace the interest groups with the groups provided or we add the provided groups to the member's interest groups (optional, defaults to true)</param>
        /// <param name="sendWelcome">optional if your double_optin is false and this is true, we will send your lists Welcome Email if this subscribe succeeds - this will *not* fire if we end up updating an existing subscriber. If double_optin is true, this has no effect. defaults to false.</param>
        /// <returns></returns>
        public EmailParameter Subscribe(string listId, EmailParameter emailParam, MergeVar mergeVars = null, string emailType = "html", bool doubleOptIn = true, bool updateExisting = false, bool replaceInterests = true, bool sendWelcome = false)
        {
            //  Our api action:
            string apiAction = "lists/subscribe";

            //  Create our arguments object:
            object args = new
            {
                apikey            = this.APIKey,
                id                = listId,
                email             = emailParam,
                merge_vars        = mergeVars,
                email_type        = emailType,
                double_optin      = doubleOptIn,
                update_existing   = updateExisting,
                replace_interests = replaceInterests,
                send_welcome      = sendWelcome
            };

            //  Make the call:
            return(MakeAPICall <EmailParameter>(apiAction, args));
        }
示例#7
0
        public void SubscribeWithGroupSelectionUsingDictonary_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();
            EmailParameter   email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            // find a list with interest groups...
            string strListID    = null;
            int    nGroupingID  = 0;
            string strGroupName = null;

            foreach (ListInfo li in lists.Data)
            {
                List <InterestGrouping> interests = mc.GetListInterestGroupings(li.Id);
                if (interests != null)
                {
                    if (interests.Count > 0)
                    {
                        if (interests[0].GroupNames.Count > 0)
                        {
                            strListID    = li.Id;
                            nGroupingID  = interests[0].Id;
                            strGroupName = interests[0].GroupNames[0].Name;
                            break;
                        }
                    }
                }
            }
            Assert.IsNotNull(strListID, "no lists found in this account with groupings / group names");
            Assert.AreNotEqual(0, nGroupingID);
            Assert.IsNotNull(strGroupName);

            MergeVar mvso = new MergeVar();

            mvso.Groupings = new List <Grouping>();
            mvso.Groupings.Add(new Grouping());
            mvso.Groupings[0].Id         = nGroupingID;
            mvso.Groupings[0].GroupNames = new List <string>();
            mvso.Groupings[0].GroupNames.Add(strGroupName);
            mvso.Add("FNAME", "Testy" + DateTime.Now);
            mvso.Add("LNAME", "Testerson" + DateTime.Now);

            //  Act
            EmailParameter results = mc.Subscribe(strListID, email, mvso);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(!string.IsNullOrEmpty(results.LEId));

            // load
            List <EmailParameter> emails = new List <EmailParameter>();

            emails.Add(results);
            MemberInfoResult memberInfos = mc.GetMemberInfo(strListID, emails);

            // Assert
            Assert.AreEqual(1, memberInfos.SuccessCount);
            Assert.AreEqual(2, memberInfos.Data[0].MemberMergeInfo.Count);
            Assert.AreEqual(mvso["FNAME"], memberInfos.Data[0].MemberMergeInfo["FNAME"]);
            Assert.AreEqual(mvso["LNAME"], memberInfos.Data[0].MemberMergeInfo["LNAME"]);
        }
        public ActionResult HandleContactSubmit(USNContactFormViewModel model)
        {
            System.Threading.Thread.Sleep(1000);

            string returnValue = String.Empty;

            if (!ModelState.IsValid)
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('{1}');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Contact Form General Error")))));
            }

            //Need to get NodeID from hidden field. CurrentPage does not work with Ajax.BeginForm
            var contactFormNode = Umbraco.TypedContent(model.CurrentNodeID);
            var globalSettings  = Umbraco.TypedContent(model.GlobalSettingsID);

            if (globalSettings.HasValue("googleReCAPTCHASiteKey") && globalSettings.HasValue("googleReCAPTCHASecretKey"))
            {
                var    response  = Request["g-recaptcha-response"];
                string secretKey = globalSettings.GetPropertyValue <string>("googleReCAPTCHASecretKey");
                var    client    = new WebClient();
                var    result    = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response));
                var    obj       = JObject.Parse(result);
                var    status    = (bool)obj.SelectToken("success");

                if (!status)
                {
                    return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('{1}');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Form reCAPTCHA Error")))));
                }
            }

            string mailTo      = contactFormNode.GetPropertyValue <string>("contactRecipientEmailAddress");
            string websiteName = globalSettings.GetPropertyValue <string>("websiteName");
            string pageName    = contactFormNode.Parent.Parent.Name;

            string errorMessage = String.Empty;

            if (!SendContactFormMail(model, mailTo, websiteName, pageName, out errorMessage))
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Contact Form Mail Send Error")), HttpUtility.JavaScriptStringEncode(errorMessage))));
            }

            try
            {
                if (model.NewsletterSignup && globalSettings.HasValue("newsletterAPIKey") &&
                    (globalSettings.HasValue("defaultNewsletterSubscriberListID") || contactFormNode.HasValue("contactSubscriberListID")))
                {
                    if (globalSettings.GetPropertyValue <USNOptions>("emailMarketingPlatform") == USNOptions.Newsletter_CM)
                    {
                        AuthenticationDetails auth = new ApiKeyAuthenticationDetails(globalSettings.GetPropertyValue <string>("newsletterAPIKey"));

                        string subsciberListID = String.Empty;

                        if (contactFormNode.HasValue("newsletterSubscriberListID"))
                        {
                            subsciberListID = contactFormNode.GetPropertyValue <string>("contactSubscriberListID");
                        }
                        else
                        {
                            subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                        }

                        Subscriber loSubscriber = new Subscriber(auth, subsciberListID);

                        List <SubscriberCustomField> customFields = new List <SubscriberCustomField>();

                        string subscriberID = loSubscriber.Add(model.Email, model.FirstName + " " + model.LastName, customFields, false);
                    }
                    else if (globalSettings.GetPropertyValue <USNOptions>("emailMarketingPlatform") == USNOptions.Newsletter_Mailchimp)
                    {
                        var mc = new MailChimpManager(globalSettings.GetPropertyValue <string>("newsletterAPIKey"));

                        string subsciberListID = String.Empty;

                        if (contactFormNode.HasValue("contactSubscriberListID"))
                        {
                            subsciberListID = contactFormNode.GetPropertyValue <string>("contactSubscriberListID");
                        }
                        else
                        {
                            subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                        }

                        var email = new EmailParameter()
                        {
                            Email = model.Email
                        };

                        var myMergeVars = new MergeVar();
                        myMergeVars.Add("FNAME", model.FirstName);
                        myMergeVars.Add("LNAME", model.LastName);

                        EmailParameter results = mc.Subscribe(subsciberListID, email, myMergeVars, "html", false, true, false, false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Contact Form Signup Error")), HttpUtility.JavaScriptStringEncode(ex.Message))));
            }

            returnValue = String.Format("<div class=\"spc alert alert-success alert-dismissible fade in\" role=\"alert\"><div class=\"info\">{0}</div></div>", contactFormNode.GetPropertyValue <string>("contactSubmissionMessage"));

            return(Content(returnValue));
        }
        public ActionResult HandleContactSubmit(USNContactFormViewModel model)
        {
            System.Threading.Thread.Sleep(1000);

            string returnValue = String.Empty;

            if (!ModelState.IsValid)
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('{1}');", model.CurrentNodeID, umbraco.library.GetDictionaryItem("USN Contact Form General Error"))));
            }

            //Need to get NodeID from hidden field. CurrentPage does not work with Ajax.BeginForm
            IPublishedContent contactFormNode = Umbraco.TypedContent(model.CurrentNodeID);

            IPublishedContent homeNode       = contactFormNode.Site();
            IPublishedContent globalSettings = homeNode.GetPropertyValue <IPublishedContent>("websiteConfigurationNode").Children.Where(x => x.IsDocumentType("USNGlobalSettings")).First();

            string mailTo      = contactFormNode.GetPropertyValue <string>("recipientEmailAddress");
            string websiteName = globalSettings.GetPropertyValue <string>("websiteName");
            string pageName    = contactFormNode.Parent.Parent.Name;

            string errorMessage = String.Empty;

            if (!SendContactFormMail(model, mailTo, websiteName, pageName, out errorMessage))
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, umbraco.library.GetDictionaryItem("USN Contact Form Mail Send Error"), errorMessage)));
            }

            try
            {
                if (model.NewsletterSignup && globalSettings.HasValue("newsletterAPIKey") &&
                    (globalSettings.HasValue("defaultNewsletterSubscriberListID") || contactFormNode.HasValue("newsletterSubscriberListID")))
                {
                    if (globalSettings.GetPropertyValue <string>("emailMarketingPlatform") == "Campaign Monitor")
                    {
                        AuthenticationDetails auth = new ApiKeyAuthenticationDetails(globalSettings.GetProperty("newsletterAPIKey").Value.ToString());

                        string subsciberListID = String.Empty;

                        if (contactFormNode.HasValue("newsletterSubscriberListID"))
                        {
                            subsciberListID = contactFormNode.GetPropertyValue <string>("newsletterSubscriberListID");
                        }
                        else
                        {
                            subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                        }

                        Subscriber loSubscriber = new Subscriber(auth, subsciberListID);

                        List <SubscriberCustomField> customFields = new List <SubscriberCustomField>();

                        string subscriberID = loSubscriber.Add(model.Email, model.FirstName + " " + model.LastName, customFields, false);
                    }
                    else if (globalSettings.GetPropertyValue <string>("emailMarketingPlatform") == "MailChimp")
                    {
                        var mc = new MailChimpManager(globalSettings.GetPropertyValue <string>("newsletterAPIKey"));

                        string subsciberListID = String.Empty;

                        if (contactFormNode.HasValue("newsletterSubscriberListID"))
                        {
                            subsciberListID = contactFormNode.GetPropertyValue <string>("newsletterSubscriberListID");
                        }
                        else
                        {
                            subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                        }

                        var email = new EmailParameter()
                        {
                            Email = model.Email
                        };

                        var myMergeVars = new MergeVar();
                        myMergeVars.Add("FNAME", model.FirstName);
                        myMergeVars.Add("LNAME", model.LastName);

                        EmailParameter results = mc.Subscribe(subsciberListID, email, myMergeVars, "html", false, true, false, false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(JavaScript(String.Format("$(ContactError{0}).show();$(ContactError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, umbraco.library.GetDictionaryItem("USN Contact Form Signup Error"), ex.Message.Replace("'", "\""))));
            }

            returnValue = String.Format("<div class=\"spc alert alert-success alert-dismissible fade in\" role=\"alert\"><div class=\"info\">{0}</div></div>", contactFormNode.GetPropertyValue <string>("submissionMessage"));

            return(Content(returnValue));
        }
        public async Task <ActionResult> HandleNewsletterSubmit(USNNewsletterFormViewModel model)
        {
            System.Threading.Thread.Sleep(1000);

            string lsReturnValue = "";

            var currentNode = Umbraco.TypedContent(model.CurrentNodeID);
            var currentPage = Umbraco.TypedContent(model.ActualPageID);

            IPublishedContent homeNode = currentPage.AncestorOrSelf(1);
            var settingsFolder         = Umbraco.TypedContent(homeNode.GetProperty("websiteConfigurationNode").Value);
            var globalSettings         = settingsFolder.Children.Where(x => x.DocumentTypeAlias == "USNGlobalSettings").First();

            if (!ModelState.IsValid)
            {
                return(JavaScript(String.Format("$(NewsletterError{0}).show();$(NewsletterError{0}).html('<div class=\"info\"><p>{1}</p></div>');", model.CurrentNodeID, umbraco.library.GetDictionaryItem("USN Newsletter Form General Error"))));
            }
            try
            {
                if (globalSettings.GetProperty("emailMarketingPlatform").Value.ToString() == "Campaign Monitor")
                {
                    AuthenticationDetails auth = new ApiKeyAuthenticationDetails(globalSettings.GetProperty("newsletterAPIKey").Value.ToString());

                    string subsciberListID = String.Empty;

                    if (currentNode.GetProperty("newsletterSubscriberListID").Value.ToString() != String.Empty)
                    {
                        subsciberListID = currentNode.GetProperty("newsletterSubscriberListID").Value.ToString();
                    }
                    else
                    {
                        subsciberListID = globalSettings.GetProperty("defaultNewsletterSubscriberListID").Value.ToString();
                    }

                    Subscriber loSubscriber = new Subscriber(auth, subsciberListID);

                    List <SubscriberCustomField> customFields = new List <SubscriberCustomField>();

                    string subscriberID = loSubscriber.Add(model.Email, model.FirstName + " " + model.LastName, customFields, false);
                }
                else if (globalSettings.GetProperty("emailMarketingPlatform").Value.ToString() == "MailChimp")
                {
                    var mc = new MailChimpManager(globalSettings.GetProperty("newsletterAPIKey").Value.ToString());

                    string subsciberListID = String.Empty;

                    if (currentNode.GetProperty("newsletterSubscriberListID").Value.ToString() != String.Empty)
                    {
                        subsciberListID = currentNode.GetProperty("newsletterSubscriberListID").Value.ToString();
                    }
                    else
                    {
                        subsciberListID = globalSettings.GetProperty("defaultNewsletterSubscriberListID").Value.ToString();
                    }


                    var email = new EmailParameter()
                    {
                        Email = model.Email
                    };

                    var myMergeVars = new MergeVar();
                    myMergeVars.Add("FNAME", model.FirstName);
                    myMergeVars.Add("LNAME", model.LastName);

                    EmailParameter results = mc.Subscribe(subsciberListID, email, myMergeVars, "html", false, true, false, false);
                }

                lsReturnValue = String.Format("<div class=\"spc alert alert-success alert-dismissible fade in\" role=\"alert\"><div class=\"info\">{0}</div></div>", currentNode.GetProperty("submissionMessage").Value.ToString());
                return(Content(lsReturnValue));
            }
            catch (Exception ex)
            {
                return(JavaScript(String.Format("$(NewsletterError{0}).show();$(NewsletterError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, umbraco.library.GetDictionaryItem("USN Newsletter Form Signup Error"), ex.Message)));
            }
        }
示例#11
0
        public ActionResult HandleNewsletterSubmit(USNNewsletterFormViewModel model)
        {
            System.Threading.Thread.Sleep(1000);

            var globalSettings = Umbraco.Content(model.GlobalSettingsID);

            string recaptchaReset = globalSettings.HasValue("googleReCAPTCHASiteKey") && globalSettings.HasValue("googleReCAPTCHASecretKey") ? "grecaptcha.reset();" : String.Empty;

            string lsReturnValue = String.Empty;

            if (!ModelState.IsValid)
            {
                return(JavaScript(String.Format("{0}$('#NE_{1}').show();$('#NE_{1}').html('<div class=\"info\"><p>{2}</p></div>');", recaptchaReset, model.UniqueID, HttpUtility.JavaScriptStringEncode(Umbraco.GetDictionaryValue("USN Form Required Field Error")))));
            }
            try
            {
                if (globalSettings.HasValue("googleReCAPTCHASiteKey") && globalSettings.HasValue("googleReCAPTCHASecretKey"))
                {
                    var    response  = Request["g-recaptcha-response"];
                    string secretKey = globalSettings.Value <string>("googleReCAPTCHASecretKey");
                    var    client    = new WebClient();
                    var    result    = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response));
                    var    obj       = JObject.Parse(result);
                    var    status    = (bool)obj.SelectToken("success");

                    if (!status)
                    {
                        return(JavaScript(String.Format("{0}$('#NE_{1}').show();$('#NE_{1}').html('{2}');", recaptchaReset, model.UniqueID, HttpUtility.JavaScriptStringEncode(Umbraco.GetDictionaryValue("USN Form reCAPTCHA Error")))));
                    }
                }

                string firstName = model.FirstName == "***" ? String.Empty : model.FirstName;
                string lastName  = model.LastName == "***" ? String.Empty : model.LastName;

                if (globalSettings.Value <string>("emailMarketingPlatform") == "newsletterCM")
                {
                    AuthenticationDetails auth = new ApiKeyAuthenticationDetails(globalSettings.Value <string>("newsletterAPIKey"));

                    string subsciberListID = String.Empty;

                    if (model.FormSubscriberListID.HasValue())
                    {
                        subsciberListID = model.FormSubscriberListID;
                    }
                    else
                    {
                        subsciberListID = globalSettings.Value <string>("defaultNewsletterSubscriberListID");
                    }

                    Subscriber loSubscriber = new Subscriber(auth, subsciberListID);

                    List <SubscriberCustomField> customFields = new List <SubscriberCustomField>();

                    string subscriberID = loSubscriber.Add(model.Email, firstName + " " + lastName, customFields, false);
                }
                else if (globalSettings.Value <string>("emailMarketingPlatform") == "newsletterMC")
                {
                    var mc = new MailChimpManager(globalSettings.Value <string>("newsletterAPIKey"));

                    string subsciberListID = String.Empty;

                    if (model.FormSubscriberListID.HasValue())
                    {
                        subsciberListID = model.FormSubscriberListID;
                    }
                    else
                    {
                        subsciberListID = globalSettings.Value <string>("defaultNewsletterSubscriberListID");
                    }


                    var email = new EmailParameter()
                    {
                        Email = model.Email
                    };

                    var myMergeVars = new MergeVar();
                    myMergeVars.Add("FNAME", firstName);
                    myMergeVars.Add("LNAME", lastName);

                    EmailParameter results = mc.Subscribe(subsciberListID, email, myMergeVars, "html", false, true, false, false);
                }

                return(JavaScript(String.Format("$('#S_{0}').show();$('#Form_{0}').hide();", model.UniqueID)));
            }
            catch (Exception ex)
            {
                return(JavaScript(String.Format("{0}$('#NE_{1}').show();$('#NE_{1}').html('<div class=\"info\"><p>{2}</p><p>{3}</p></div>');", recaptchaReset, model.UniqueID, HttpUtility.JavaScriptStringEncode(Umbraco.GetDictionaryValue("USN Newsletter Form Signup Error")), HttpUtility.JavaScriptStringEncode(ex.Message))));
            }
        }
示例#12
0
        private static IApiResponse <AddSubscriberResponse> AddSubscriber(string email, MergeVar mergeVar)
        {
            var mailchimpManager = new MailchimpManager(_apiKey);

            var response = mailchimpManager.ListAction(ListId).AddSubscriber(email, mergeVar);

            return(response);
        }
示例#13
0
        public async Task <IApiResponse <AddSubscriberResponse> > AddSubscriberAsync(string email, MergeVar mergeVar)
        {
            var subscriber = SubscriberBuilder.Build(email, SubscriberStatus.Subscribed, mergeVar);

            return(await AddSubscriberAsync(subscriber));
        }
示例#14
0
        public IApiResponse <AddSubscriberResponse> AddSubscriber(string email, MergeVar mergeVar)
        {
            var subscriber = SubscriberBuilder.Build(email, SubscriberStatus.Subscribed, mergeVar);

            return(AddSubscriber(subscriber));
        }
示例#15
0
        public void ProcessMailChimpQueueMessage([QueueTrigger("%MailChimpQueue%")] string message, TextWriter log)
        {
            log.WriteLine("Message received: {0}", message);
            Console.WriteLine(message);

            // Read the configuration.
            var mailChimpApiKey        = CloudConfigurationManager.GetSetting(MailChimpApiKey);
            var mailChimpListId        = CloudConfigurationManager.GetSetting(MailChimpListIdKey);
            var mailChimpGroupId       = CloudConfigurationManager.GetSetting(MailChimpGroupIdKey);
            var mailChimpGroupNameList = GetGroupNameList();

            // Convert the message to a model.
            var user             = JsonConvert.DeserializeObject <MarketingData>(message);
            var mailchimpManager = new MailChimpManager(mailChimpApiKey);

            // Create an instance of the merge variable.
            var mergeVars = new MergeVar {
                Groupings = new List <Grouping> {
                    new Grouping()
                }
            };

            mergeVars.Add("COMPANY", user.CompanyName);
            mergeVars.Add("AREAS", user.Areas.ToString());
            mergeVars.Add("METRICS", user.Metrics.ToString());
            mergeVars.Add("GOALCOUNT", user.Goals.ToString());
            mergeVars.Add("REPS_START", user.ReportsStarted.ToString());
            mergeVars.Add("REPS_COMP", user.ReportsCompleted.ToString());
            mergeVars.Add("REPS_SENT", user.ReportsSent.ToString());
            mergeVars.Add("REPSCOUNT", user.ReportsTotal.ToString());
            mergeVars.Add("LOGINS", user.LoginCount.ToString());
            mergeVars.Add("LASTLOGIN", user.LastLogin.ToString(@"MM\/dd\/yyyy HH:mm"));
            mergeVars.Add("SUB_STATUS", user.SubscriptionStatus.ToString());
            mergeVars.Add("SUB_EXPIRY", user.SubscriptionExpiryDate.ToString(@"MM\/dd\/yyyy HH:mm"));

            // New user
            if (string.IsNullOrEmpty(user.OldEmail))
            {
                // Create an instance of email parameter.
                var emailParameter = new EmailParameter {
                    Email = user.Email
                };

                // Set the default groups.
                mergeVars.Groupings[0].Id         = int.Parse(mailChimpGroupId, NumberStyles.Integer);
                mergeVars.Groupings[0].GroupNames = mailChimpGroupNameList;

                // Subscribe to the configured MailChimp list.
                mailchimpManager.Subscribe(mailChimpListId, emailParameter, mergeVars, updateExisting: true, doubleOptIn: false, sendWelcome: false);
            }
            else
            {
                // Case of existing user changed an email address.

                // Create an instance of email parameter.
                var emailParameter = new EmailParameter {
                    Email = user.OldEmail
                };
                mergeVars.Add("NEW-EMAIL", user.Email);

                // Update the email address.
                mailchimpManager.UpdateMember(mailChimpListId, emailParameter, mergeVars, replaceInterests: false);
            }

            Console.WriteLine("Email {0} successfully pushed to MailChimp", user.Email);
        }
示例#16
0
        public ActionResult HandleNewsletterSubmit(USNNewsletterFormViewModel model)
        {
            System.Threading.Thread.Sleep(1000);

            string lsReturnValue = String.Empty;

            var currentNode    = Umbraco.TypedContent(model.CurrentNodeID);
            var globalSettings = Umbraco.TypedContent(model.GlobalSettingsID);

            if (!ModelState.IsValid)
            {
                return(JavaScript(String.Format("$(NewsletterError{0}).show();$(NewsletterError{0}).html('<div class=\"info\"><p>{1}</p></div>');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Newsletter Form General Error")))));
            }
            try
            {
                if (globalSettings.GetPropertyValue <string>("emailMarketingPlatform") == "Campaign Monitor")
                {
                    AuthenticationDetails auth = new ApiKeyAuthenticationDetails(globalSettings.GetPropertyValue <string>("newsletterAPIKey"));

                    string subsciberListID = String.Empty;

                    if (currentNode.GetPropertyValue <string>("newsletterSubscriberListID") != String.Empty)
                    {
                        subsciberListID = currentNode.GetPropertyValue <string>("newsletterSubscriberListID");
                    }
                    else
                    {
                        subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                    }

                    Subscriber loSubscriber = new Subscriber(auth, subsciberListID);

                    List <SubscriberCustomField> customFields = new List <SubscriberCustomField>();

                    string subscriberID = loSubscriber.Add(model.Email, model.FirstName + " " + model.LastName, customFields, false);
                }
                else if (globalSettings.GetPropertyValue <string>("emailMarketingPlatform") == "MailChimp")
                {
                    var mc = new MailChimpManager(globalSettings.GetPropertyValue <string>("newsletterAPIKey"));

                    string subsciberListID = String.Empty;

                    if (currentNode.HasValue("newsletterSubscriberListID"))
                    {
                        subsciberListID = currentNode.GetPropertyValue <string>("newsletterSubscriberListID");
                    }
                    else
                    {
                        subsciberListID = globalSettings.GetPropertyValue <string>("defaultNewsletterSubscriberListID");
                    }


                    var email = new EmailParameter()
                    {
                        Email = model.Email
                    };

                    var myMergeVars = new MergeVar();
                    myMergeVars.Add("FNAME", model.FirstName);
                    myMergeVars.Add("LNAME", model.LastName);

                    EmailParameter results = mc.Subscribe(subsciberListID, email, myMergeVars, "html", false, true, false, false);
                }

                lsReturnValue = String.Format("<div class=\"spc alert alert-success alert-dismissible fade in\" role=\"alert\"><div class=\"info\">{0}</div></div>", currentNode.GetPropertyValue <string>("submissionMessage"));
                return(Content(lsReturnValue));
            }
            catch (Exception ex)
            {
                return(JavaScript(String.Format("$(NewsletterError{0}).show();$(NewsletterError{0}).html('<div class=\"info\"><p>{1}</p><p>{2}</p></div>');", model.CurrentNodeID, HttpUtility.JavaScriptStringEncode(umbraco.library.GetDictionaryItem("USN Newsletter Form Signup Error")), HttpUtility.JavaScriptStringEncode(ex.Message))));
            }
        }