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); } }
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)); }
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); } }
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); } }