Beispiel #1
0
        public void Send(String idUser, String firstName, String email)
        {
            String emailAPI = ConfigurationManager.AppSettings["MailChimpAPI"].ToString();

            MailChimpManager mc = new MailChimpManager(emailAPI);

            ListResult lists = mc.GetLists();

            EmailConfirm emailConfirm = new EmailConfirm();
            //emailConfirm.Groupings = new List<Grouping>();
            //emailConfirm.Groupings.Add(new Grouping());
            //emailConfirm.Groupings[0].Id = 1234; // replace with your grouping id
            //emailConfirm.Groupings[0].GroupNames = new List<string>();
            //emailConfirm.Groupings[0].GroupNames.Add("Your Group Name");
            emailConfirm.FirstName = firstName;
            emailConfirm.IdUser = idUser;

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

            //            ListResult lr = mc.GetLists();
            EmailParameter results = mc.Subscribe("d31fd680be", parameters, emailConfirm);
        }
        public ActionResult Update(string id)
        {
            var defaultEvent = service.GetDefaultEvent();
            int eventid = defaultEvent.ID;
            MailChimpManager mc = new MailChimpManager(_mailchimpKey);
            ListInfo mailingList = mc.GetLists().Data.Where(l=>l.Id==id).SingleOrDefault();
            List<BatchEmailParameter> batchList = new List<BatchEmailParameter>();
            if (mailingList.Name.Contains("Speakers"))
            {
                foreach (var speaker in service.GetSpeakers(eventid))
                {
                    MyMergeVar myMergeVars = new MyMergeVar();
                    myMergeVars.FirstName = speaker.FirstName;
                    myMergeVars.LastName = speaker.LastName;           //  Create the email parameter
                    BatchEmailParameter batchEmail = new BatchEmailParameter();
                    EmailParameter email = new EmailParameter()
                    {
                        Email = speaker.Email

                    };
                    batchEmail.Email = email;
                    batchEmail.MergeVars = myMergeVars;

                    batchList.Add(batchEmail);
                }
            }
            if (mailingList.Name.Contains("Attendees"))
            {
                foreach (var attendee in service.GetAllAttendees(eventid))
                {
                    MyMergeVar myMergeVars = new MyMergeVar();
                    myMergeVars.FirstName = attendee.FirstName;
                    myMergeVars.LastName = attendee.LastName;           //  Create the email parameter
                    EmailParameter email = new EmailParameter()
                    {
                        Email = attendee.Email
                    };
                    BatchEmailParameter batchEmail = new BatchEmailParameter();
                    batchEmail.Email = email;
                    batchEmail.MergeVars = myMergeVars;

                    batchList.Add(batchEmail);

                }

            }
            BatchSubscribeResult bResult = mc.BatchSubscribe(id, batchList, false, true, true);
            //MyMergeVar myMergeVars = new MyMergeVar();
            //myMergeVars.FirstName = subscriber.FirstName;
            //myMergeVars.LastName = subscriber.LastName;           //  Create the email parameter
            //EmailParameter email = new EmailParameter()
            //{
            //    Email = subscriber.EmailAddress
            //};

            //EmailParameter results = mc.Subscribe(_mailchimpGroupId, email, myMergeVars);

            return RedirectToAction("Index");
        }
        // POST api/mailchimp
        public string Post(Subscriber subscriber)
        {
            MailChimpManager mc = new MailChimpManager(_mailchimpKey);
            MyMergeVar myMergeVars = new MyMergeVar();
            myMergeVars.FirstName = subscriber.FirstName;
            myMergeVars.LastName = subscriber.LastName;           //  Create the email parameter
            EmailParameter email = new EmailParameter()
            {
                Email = subscriber.EmailAddress
            };

            EmailParameter results = mc.Subscribe(_mailchimpGroupId, email, myMergeVars);
            return results.LEId;
        }
Beispiel #4
0
        public void Subscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();
            EmailParameter email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            //  Act
            EmailParameter results = mc.Subscribe(lists.Data[1].Id, email);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(!string.IsNullOrEmpty(results.LEId));
        }
        // MailChimp campaign methods
        public EmailParameter AddSubscriber(string emailAddress, string fname, string lname)
        {
            var list = _listId;

            Models.MailChimpCampaignModel.MergeFields userFields = new Models.MailChimpCampaignModel.MergeFields();
            userFields.FirstName = fname;
            userFields.LastName = lname;

            MailChimpManager mc = new MailChimpManager(_apiKey);

            EmailParameter email = new EmailParameter()
            {
                Email = emailAddress
            };

            EmailParameter result = mc.Subscribe(list, email, userFields);

            return result;
        }
Beispiel #6
0
        public bool Subscribe(string email, int domainID)
        {
            tbl_Domains domain = DomainsRepository.GetByID(domainID);
            if (domain == null || !domain.DO_EnableMailChimp)
                return false;

            MailChimpManager manager = new MailChimpManager(domain.DO_MailChimpAPIKey);
            EmailParameter emailParam = new EmailParameter() { Email = email };
            try
            {
                var val = manager.Subscribe(domain.DO_MailChimpListID, emailParam, updateExisting: true);
                return val != null ? true : false;
            }
            catch (MailChimpAPIException e)
            {
                Log.Error(String.Format("MailChimp Subscribe: Subscription exception: \"{0}\" ,for \"{1}\"", e.MailChimpAPIError.Name, email), e);
            }
            return false;
        }
Beispiel #7
0
        public bool GetSubscriptionStatus(string email, int domainID)
        {
            tbl_Domains domain = DomainsRepository.GetByID(domainID);
            if (domain == null || !domain.DO_EnableMailChimp)
                return false;

            MailChimpManager manager = new MailChimpManager(domain.DO_MailChimpAPIKey);
            EmailParameter emailParam = new EmailParameter() { Email = email };
            try
            {
                var val = manager.GetListsForEmail(emailParam);
                return val != null && val.Count > 0 ? true : false;
            }
            catch (MailChimpAPIException e)
            {
                Log.Error(String.Format("MailChimp Status: Subscription exception: \"{0}\" ,for \"{1}\"", e.MailChimpAPIError.Name, email), e);
            }
            return false;
        }
        public IHttpActionResult Subscribe(string subscribeEmail)
        {
            EmailParameter result;
            if (!string.IsNullOrEmpty(_mailingSettings.AccessToken) && !string.IsNullOrEmpty(_mailingSettings.AccessToken) && !string.IsNullOrEmpty(_mailingSettings.SubscribersListId) &&
                subscribeEmail.Contains("@") && subscribeEmail.Contains("."))
            {
                var mc = new MailChimpManager(_mailingSettings.AccessToken, _mailingSettings.DataCenter);

                //  Create the email parameter
                var email = new EmailParameter()
                {
                    Email = subscribeEmail,
                };

                result = mc.Subscribe(_mailingSettings.SubscribersListId, email);
                if (string.IsNullOrEmpty(result.EUId))
                    return BadRequest();
            }
            else
            {
                return BadRequest();
            }
            return Ok(result);
        }
        public static EmailParameter AddEmail(string email)
        {
            try
            {
                var apiKey = ConfigurationManager.AppSettings["MailChimpApiKey"];
                var listId = ConfigurationManager.AppSettings["MailChimpListId"];

                var mc = new MailChimpManager(apiKey);

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

                var result = mc.Subscribe(listId, emailParam, doubleOptIn: false);
                return result;
            }
            catch (Exception)
            {
            }

            return null;
        }
Beispiel #10
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"]);

				}
Beispiel #11
0
 public void DeleteStaticSegmentMembers_Successful()
 {
     MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
     ListResult lists = mc.GetLists();
     List<StaticSegmentResult> segments = mc.GetStaticSegmentsForList(lists.Data[1].Id);
     EmailParameter email1 = new EmailParameter()
     {
         Email = "*****@*****.**"
     };
     List<EmailParameter> emails = new List<EmailParameter>();
     emails.Add(email1);
     StaticSegmentMembersDeleteResult result = mc.DeleteStaticSegmentMembers(lists.Data[1].Id, segments[0].StaticSegmentId, emails);
     Assert.IsTrue(result.successCount == 1);
     Assert.IsTrue(result.errorCount == 0);
 }
Beispiel #12
0
        public void GetMemberInfo_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();

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

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

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

            emails.Add(email1);
            emails.Add(email2);

            //  Act
            MemberInfoResult results = mc.GetMemberInfo(lists.Data[1].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
        }
Beispiel #13
0
        public void BatchUnsubscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();

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

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

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

            emails.Add(email1);
            emails.Add(email2);

            //  Act
            BatchUnsubscribeResult results = mc.BatchUnsubscribe(lists.Data[1].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.SuccessCount == 2);
        }
Beispiel #14
0
        public void Unsubscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();
            EmailParameter email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            //  Act
            UnsubscribeResult results = mc.Unsubscribe(lists.Data[1].Id, email);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.Complete);
        }
        public void SubscribeWithGroupSelection_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);

            MyMergeVar mvso = new MyMergeVar();
            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.FirstName = "Testy";
            mvso.LastName = "Testerson";

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

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(!string.IsNullOrEmpty(results.LEId));
        }
        public ActionResult RegisterHouseholdMembers(HouseholdMemberModel householdMemberModel)
        {
            AddressModel address = new UserService().GetAddressById(householdMemberModel.AddressId);

            //Don't allow duplicate user
            var tryToFindUser = Membership.GetUserNameByEmail(householdMemberModel.Email);
            if (string.IsNullOrEmpty(tryToFindUser))
            {

                var id = Guid.NewGuid();

                Boolean isFBUser = false;
                Boolean isApproved = true;
                Int32 FBUserId = 0;

                // create the ASP membership user
                MembershipCreateStatus status;
                var membershipUser = Membership.CreateUser(username: householdMemberModel.Email, password: householdMemberModel.Password, email: householdMemberModel.Email,
                    passwordQuestion: null, passwordAnswer: null,
                    isApproved: isApproved, providerUserKey: id,
                    status: out status
                );

                // Check inviter user role and the same role for invited user
                var addressHolderUserEmail = new UserService().GetUserNameHolderForAddress(householdMemberModel.AddressId);
                if (!string.IsNullOrWhiteSpace(addressHolderUserEmail))
                {
                    if (Roles.IsUserInRole(addressHolderUserEmail, "Supplier") && membershipUser != null)
                    {
                        Roles.AddUserToRole(membershipUser.Email, "Supplier");
                    }
                }

                if (status == MembershipCreateStatus.Success)
                {
                    // create the GM user
                    var user = new UserModel
                    {
                        Id = id,
                        FirstName = householdMemberModel.FirstName,
                        LastName = householdMemberModel.LastName,
                        AddressModel = address,
                        AddressId = address.Id,
                        Instance_Id = address.Instance_Id,
                        SendEmailOffers = householdMemberModel.SendEmailOffers,
                        SendEmailUpdates = householdMemberModel.SendEmailUpdates,
                        IsFBAccount = isFBUser,
                        FBUserId = FBUserId,
                        IsAdditionalAccountHolder = true
                    };

                    // Give them the New Member Bonus
                    int numBonusPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.NewMember.Points"]);
                    string descBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.NewMember.Description"]);
                    int? transactionTypeId = Convert.ToInt16(ConfigurationManager.AppSettings["TransactionType.ShareHeart"]);

                    // store it
                    var newUser = new UserService().CreateUser(user, numBonusPoints, descBonusPoints, transactionTypeId);

                    int numBonusInvitationAcceptedPoints = Convert.ToInt16(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Points"]);
                    string descInvitationAcceptedBonusPoints = Convert.ToString(ConfigurationManager.AppSettings["BonusPoints.InviteMember.Description"]);

                    bool addPoints = new UserService().InvitationAcceptedAddBonusPoints(addressHolderUserEmail,
                        numBonusInvitationAcceptedPoints, descInvitationAcceptedBonusPoints, transactionTypeId);

                    SendVerifyEmail(membershipUser.Email, user.FirstName, user.Id, true);

                    bool isProduction = Convert.ToBoolean(ConfigurationManager.AppSettings["MailChimp.ListId"]);

                    if (isProduction)
                    {
                        // Add them to the relevant MailChimp List
                        MailChimpManager mc = new MailChimpManager(ConfigurationManager.AppSettings["MailChimp.APIKey"]);
                        EmailParameter email = new EmailParameter()
                        {
                            Email = user.Email
                        };

                        EmailParameter results = mc.Subscribe(ConfigurationManager.AppSettings["MailChimp.ListId"], email);

                    }

                    return RedirectToAction("RegisterAccountSuccess");

                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(status));
                    return View(householdMemberModel);
                }
            }
            else
            {
                // email has already been registered in the system
                ModelState.AddModelError("", "User with the same email address has already been registered with GreenMoney.");
                return View(householdMemberModel);

            }
        }
        /// <summary>
        /// Batches the subscribe.
        /// </summary>
        /// <param name="recordList">The records</param>
        public virtual BatchSubscribeResult BatchSubscribe(IEnumerable<MailChimpEventQueueRecord> recordList)
        {
            if (string.IsNullOrEmpty(_mailChimpSettings.DefaultListId))
                throw new ArgumentException("MailChimp list is not specified");

            var mc = new MailChimpManager(_mailChimpSettings.ApiKey);
            var batchEmailParam = new List<BatchEmailParameter>();

            foreach (var sub in recordList)
            {
                try
                {
                    var emailParam = new EmailParameter
                    {
                        Email = sub.Email
                    };

                    var mergeVars = new MergeVar();

                    // TODO Customize your merge vars

                    // get customer and attributes
                    var customer = _customerService.GetCustomerByEmail(sub.Email);
                    if (customer != null)
                    {
                        AddAttribute(mergeVars, customer, SystemCustomerAttributeNames.FirstName, "FNAME");
                        AddAttribute(mergeVars, customer, SystemCustomerAttributeNames.LastName, "LNAME");
                        AddAttribute(mergeVars, customer, SystemCustomerAttributeNames.Phone, "PHONE");

                        var gender = customer.GetAttribute<string>(SystemCustomerAttributeNames.Gender);
                        switch (gender)
                        {
                            case "F":
                                mergeVars.Add("GENDER", "Mujer");
                                break;
                            case "M":
                                mergeVars.Add("GENDER", "Hombre");
                                break;
                            default:
                                mergeVars.Add("GENDER", "No especificado");
                                break;
                        }
                    }

                    //add to group
                    mergeVars.Groupings = new List<Grouping>() {new Grouping()};
                    mergeVars.Groupings[0].Name = "Yo soy";
                    mergeVars.Groupings[0].GroupNames = new List<string> { "Deportista" };

                    batchEmailParam.Add(new BatchEmailParameter()
                    {
                        Email = emailParam,
                        MergeVars = mergeVars
                    });
                }
                catch (Exception ex)
                {
                    _log.Warning(string.Format("Could not register email {0} to Mailchimp", sub.Email), ex);
                }
            }

            BatchSubscribeResult results = mc.BatchSubscribe(_mailChimpSettings.DefaultListId, batchEmailParam, true, true, false);
            return results;
        }
Beispiel #18
0
        public void UpdateMember_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();
            EmailParameter email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };
            var listId = lists.Data[0].Id;
            MyMergeVar mergeVar = new MyMergeVar();
            EmailParameter subscriptionResults = mc.Subscribe(listId, email, mergeVar, "html", false, true);

            //  Act
            mergeVar.FirstName = "some name";
            mc.UpdateMember(listId, subscriptionResults, mergeVar);

            // load
            List<EmailParameter> emails = new List<EmailParameter>();
            emails.Add(email);
            MemberInfoResult memberInfos = mc.GetMemberInfo(listId, emails);

            //  Assert
            Assert.IsTrue(memberInfos.Data[0].MemberMergeInfo.ContainsKey("FNAME"));
            Assert.AreEqual("some name", memberInfos.Data[0].MemberMergeInfo["FNAME"]);
        }
Beispiel #19
0
        public bool UnSubscribe(string email, int domainID)
        {
            tbl_Domains domain = DomainsRepository.GetByID(domainID);
            if (domain == null || !domain.DO_EnableMailChimp)
                return false;

            MailChimpManager manager = new MailChimpManager(domain.DO_MailChimpAPIKey);
            EmailParameter emailParam = new EmailParameter() { Email = email };
            try
            {
                var result = manager.Unsubscribe(domain.DO_MailChimpListID, emailParam);
                return result != null ? result.Complete : false;
            }
            catch (MailChimpAPIException e)
            {
                Log.Error(String.Format("MailChimp UnSubscribe: Subscription exception: \"{0}\" ,for \"{1}\"", e.MailChimpAPIError.Name, email), e);
            }
            return false;
        }