//public bool SubscribeToList(string EmailAddress, string FirstName,string LastName, // string Subject, string Body, string EmailFrom, string DisplayName) //{ // lblError.Text=string.Empty; // listSubscribeInput input = new listSubscribeInput(); // input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial; // input.api_CustomErrorMessages = true; // input.parms.email_address = txtEmail.Text.ToString(); // input.parms.send_welcome = true; // input.parms.update_existing = false; // input.parms.replace_interests = true; // input.parms.double_optin = false; // //input.parms.merge_vars.Add("FNAME", FirstName); // //input.parms.merge_vars.Add("LNAME", LastName); // input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST; // input.api_Validate = true; // input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML; // input.parms.apikey = System.Configuration.ConfigurationSettings.AppSettings["MailChimpApiKey"].ToString(); // //input.parms.id = List(); // listSubscribe Subscribe = new listSubscribe(); // listSubscribeOutput output = Subscribe.Execute(input); // if (output.api_ErrorMessages.Count > 0) // { // string ErrorCode = output.api_ErrorMessages.FirstOrDefault().code; // string Error = "Error occured. " + output.api_ErrorMessages.FirstOrDefault().error; // lblError.Text = ErrorCode + "</br>" + error; // return false; // } // else // { // lblError.Text = output.result; // } // return output.result; //} protected void btnSubmit_Click(object sender, EventArgs e) { lblError.Text = string.Empty; listSubscribeInput input = new listSubscribeInput(); input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial; input.api_CustomErrorMessages = true; input.parms.email_address = txtEmail.Text.ToString(); input.parms.send_welcome = true; input.parms.update_existing = false; input.parms.replace_interests = true; input.parms.double_optin = false; input.parms.merge_vars.Add("EMAIL", txtEmail.Text.ToString()); //input.parms.merge_vars.Add("FNAME", FirstName); //input.parms.merge_vars.Add("LNAME", LastName); input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST; input.api_Validate = true; input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML; input.parms.apikey = System.Configuration.ConfigurationSettings.AppSettings["MailChimpApiKey"].ToString(); input.parms.id = "98b361abcb"; listSubscribe Subscribe = new listSubscribe(); listSubscribeOutput output = Subscribe.Execute(input); if (output.api_ErrorMessages.Count > 0) { string ErrorCode = output.api_ErrorMessages.FirstOrDefault().code; string Error = "Error occured. " + output.api_ErrorMessages.FirstOrDefault().error; lblError.Text = ErrorCode + "</br>" + Error; //return false; } else { lblError.Text = output.result.ToString(); } txtEmail.Text = string.Empty; //return output.result; }
public bool AddUserToMailingList(RequestMailingCommand command) { var input = new listSubscribeInput { api_Validate = true, parms = { // TODO: this id needs to come from a config file. id = "", // "Interested in MueVue List ID" email_address = command.Email, email_type = command.HtmlEmail ? EnumValues.emailType.html : EnumValues.emailType.text, apikey = MCAPISettings.default_apikey, double_optin = false, replace_interests = false, update_existing = true, merge_vars = new Dictionary<string, object> { {"OPTIN_IP", command.Ip}, {"OPTIN_TIME", DateTime.UtcNow.ToString()}, {"FNAME", command.FirstName}, {"LNAME", command.LastName} }, }, api_AccessType = EnumValues.AccessType.Serial, api_OutputType = EnumValues.OutputType.JSON }; var cmd = new listSubscribe(input); var output = cmd.Execute(); bool mailingListSuccess = output.result; logger.Info(String.Format("MailChimp result - {0}, {1}", mailingListSuccess, output.api_ErrorMessages)); return mailingListSuccess; }
/// <summary> /// Gets the list subscribe input. /// </summary> /// <param name="apikey">The apikey.</param> /// <param name="mailChimpListId">The mail chimp list id.</param> /// <returns></returns> private static listSubscribeInput GetListSubscribeInput(string apikey, string mailChimpListId) { var listSubscribeInput = new listSubscribeInput { parms = { apikey = apikey, id = mailChimpListId, double_optin = false, replace_interests = true, update_existing = true, send_welcome = false } }; return(listSubscribeInput); }
/// <summary> /// MaqilChimp Integartion /// </summary> /// <param name="userType"></param> /// <returns></returns> private bool AddMailChimpSubscriber(int userType) { bool returnVal = false; try { if (chkAgreeReceiveNewsletters.Checked == true) { listSubscribeInput input = new listSubscribeInput(); listSubscribe Subscribe = new listSubscribe(); input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial; input.api_CustomErrorMessages = true; input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST; input.api_Validate = true; input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML; input.parms.email_address = txtEmail.Text; input.parms.send_welcome = true; input.parms.update_existing = true; input.parms.replace_interests = true; input.parms.double_optin = false; input.parms.apikey = WebConfig.MailChimpApiKeyNew; input.parms.id = WebConfig.UserNewsLetterListID; input.parms.merge_vars.Add("EMAIL", txtEmail.Text); // ------------------------------ address List<interestGroupings> groupings = new List<interestGroupings>(); interestGroupings ig = new interestGroupings { name = "Account Status", groups = new List<string> { "New User Personal" } }; if (userType == 2) { ig = new interestGroupings { name = "Account Status", groups = new List<string> { "New User Business" } }; } groupings.Add(ig); input.parms.merge_vars.Add("groupings", groupings); // execution listSubscribeOutput output = Subscribe.Execute(input); //phase-1 enhancement if ((output != null) && (output.api_ErrorMessages.Count > 0)) { string ErrorCode = output.api_ErrorMessages.FirstOrDefault().code; string Error = "Error occured. " + output.api_ErrorMessages.FirstOrDefault().error; lblErrMsg.InnerHtml = ShowMessage(headertext, ErrorCode + "</br>" + Error, 1); lblErrMsg.Visible = true; returnVal = false; } else { if (output.result == true) { returnVal = true; } } } } catch (Exception ex) { lblErrMsg.InnerHtml = ShowMessage(headertext, ex.Message, 1); lblErrMsg.Visible = true; returnVal = false; } return returnVal; }
/// <summary> /// MaqilChimp Integartion /// </summary> /// <param name="UserType"></param> /// <returns></returns> private bool AddMailChimpSubscriber(int OldTributePackageId, int NewTributePackageId) { bool returnVal = false; try { listSubscribe Subscribe = new listSubscribe(); listSubscribeInput input = new listSubscribeInput(); StateManager stateManager = StateManager.Instance; SessionValue objSessionvalue = (SessionValue)stateManager.Get("objSessionvalue", StateManager.State.Session); List<UserInfo> objAdminList = new List<UserInfo>(); objAdminList = _presenter.GetTributeAdmins(); foreach (UserInfo objUInfo in objAdminList) { #region subscribe with useremail and package id input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial; input.api_CustomErrorMessages = true; input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST; input.api_Validate = true; input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML; input.parms.email_address = objSessionvalue.UserEmail; input.parms.send_welcome = true; input.parms.update_existing = true; input.parms.replace_interests = true; input.parms.double_optin = false; input.parms.apikey = WebConfig.MailChimpApiKeyNew; input.parms.id = WebConfig.UserNewsLetterListID; // ------------------------------ address List<Dictionary<string, object>> batch = new List<Dictionary<string, object>>(); Dictionary<string, object> entry = new Dictionary<string, object>(); List<interestGroupings> groupings = new List<interestGroupings>(); input.parms.merge_vars.Add("EMAIL", objSessionvalue.UserEmail); //create list of packages subscribed as per packages available wrt to a userid. IList<int> iPackageList = new List<int>(); iPackageList = _presenter.GetMyTributesPackages(objUInfo.UserID); string strPackageGroup = string.Empty; string packageGroup = string.Empty; foreach (int packId in iPackageList) { packageGroup = FetchInterestGroupOnPackage(packId); if (!strPackageGroup.Contains(packageGroup)) { if (string.IsNullOrEmpty(strPackageGroup)) { strPackageGroup = packageGroup; } else { strPackageGroup = strPackageGroup + " , " + packageGroup; } } } interestGroupings ig = FetchInterestOnPackage(NewTributePackageId, strPackageGroup); groupings.Add(ig); input.parms.merge_vars.Add("groupings", groupings); // execution listSubscribeOutput output = Subscribe.Execute(input); //phase-1 enhancement if ((output != null) && (output.api_ErrorMessages.Count > 0)) { //string ErrorCode = output.api_ErrorMessages.ToString(); //string Error = "Error occured. " + output.api_ErrorMessages.FirstOrDefault().error; //lblErrMsg.InnerHtml = output.api_ErrorMessages.ToString(); //lblErrMsg.Visible = true; returnVal = false; } else { if (output.result == true) { returnVal = true; } } #endregion } } catch (Exception ex) { returnVal = false; } return returnVal; }
public bool Subscribe(String listId, String subscribeEmail, Dictionary<String, object> mergeVars, String emailType, Dictionary<int, List<String>> interestGroups = null) { subscribeAddIntererestGroupsToMergeVars(interestGroups, mergeVars); EnumValues.emailType emailTypeEnum; try { emailTypeEnum = (EnumValues.emailType) Enum.Parse(typeof(EnumValues.emailType), emailType); } catch { emailTypeEnum = EnumValues.emailType.html; } // Send data to API var subscribeInput = new listSubscribeInput(MailChimpSettings.ApiKey, listId, subscribeEmail, mergeVars, emailTypeEnum, true, false, true, false); var subscribeCommand = new listSubscribe(subscribeInput); var result = subscribeCommand.Execute(); // Check for errors if (result.api_ErrorMessages.Count > 0) { var a = result.api_ErrorMessages.Select(t => t.error); throw new Exception("API errors: " + String.Join(",", a)); } if (result.api_ValidatorMessages.Count > 0) { var a = result.api_ValidatorMessages.Select(t => t.MessageText); throw new Exception(String.Join(",", a)); } return result.result; }