public async Task EventSignup(EventSignupForm input) { if (string.IsNullOrWhiteSpace(input.MailchimpGroupId)) { Logger.Error <MailchimpApiController>("Unknown mailchimp group id"); throw new Exception("Unknown mailchimp group id"); } var mailChimpManager = new MailChimpManager(AppSettings.CandidContribs.MailchimpApi.Key); var audienceId = AppSettings.CandidContribs.MailchimpApi.AudienceId; var member = new MailChimp.Net.Models.Member { EmailAddress = input.Email, StatusIfNew = Status.Subscribed }; if (!string.IsNullOrWhiteSpace(input.First)) { member.MergeFields.Add("FNAME", input.First); } if (!string.IsNullOrWhiteSpace(input.Last)) { member.MergeFields.Add("LNAME", input.Last); } // member.MergeFields.Add("COUNTRY", "Spain"); member.Interests.Add(input.MailchimpGroupId, true); await mailChimpManager.Members.AddOrUpdateAsync(audienceId, member); }
public static void AddSubscriberToList(String ListID, String Email, String FirstName, String LastName) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { MailChimp.Net.Models.Member m = new MailChimp.Net.Models.Member(); m.ListId = ListID; m.EmailAddress = Email; m.Status = MailChimp.Net.Models.Status.Undefined; // we use 'Name' and |*NAME*| on MailChimp campaigns rather than the default 'First Name' |*FNAME*| and 'Last Name' |*LNAME*| m.MergeFields.Add("NAME", (FirstName + " " + LastName).Trim()); //m.MergeFields.Add("FNAME", FirstName); //m.MergeFields.Add("LNAME", LastName); try { Manager.Members.AddOrUpdateAsync(ListID, m); // insert into datageek String uqry = "UPDATE dbl_mail_chimp_list SET Subscribers=Subscribers+1 WHERE MailChimpListID=@ListID"; SQL.Update(uqry, "@ListID", ListID); DataGeekLists = SQL.SelectDataTable("SELECT * FROM dbl_mail_chimp_list WHERE Deleted=0", null, null); String iqry = "INSERT IGNORE INTO dbl_mail_chimp_list_subscriber (ListID, Email, Subscribed) VALUES ((SELECT ListID FROM dbl_mail_chimp_list WHERE MailChimpListID=@ListID), @Email, @Subscribed)"; SQL.Insert(iqry, new String[] { "@ListID", "@Email", "@Subscribed" }, new Object[] { ListID, Email, 0 }); } catch { } }); }
public ActionResult SendMail(NewsletterSubscription model) { UmbracoHelper h = ContentHelper.GetHelper(); string email = model.EmailAddress; string apiKey = h.TypedContent(model.PageId) .AncestorOrSelf(1) .Descendant <ConfigGlobalSettings>() .MailChimpApikey; string listId = h.TypedContent(model.PageId) .AncestorOrSelf(1) .Descendant <ConfigGlobalSettings>() .MailChimpListID; if (!ModelState.IsValid) { return(Json(new { Success = false })); } IMailChimpManager manager = new MailChimpManager(apiKey); //var listId = listI" 0d3a461bf3"; var member = new MailChimp.Net.Models.Member { EmailAddress = email, Status = Status.Subscribed }; manager.Members.AddOrUpdateAsync(listId, member); return(Json(new { Success = true })); }
public async Task<Member> AddMemberAsync(string listId, string segmentId, Member member) { using (var client = this.CreateMailClient(string.Format(BaseUrl + "/", listId))) { var response = await client.PostAsJsonAsync(segmentId + "/members", member).ConfigureAwait(false); await response.EnsureSuccessMailChimpAsync().ConfigureAwait(false); var memberResponse = await response.Content.ReadAsAsync<Member>().ConfigureAwait(false); return memberResponse; } }
private async Task AddNewMember() { var member = new Member { EmailAddress = $"{_ticks}@test.com", Status = Status.Subscribed }; member.MergeFields.Add("FNAME", "HOLY COW"); await _mailChimpManager.Members.AddOrUpdateAsync("72dcc9fa45", member); }
public async Task Unsubscribe_User_From_List() { var member = new Member { EmailAddress = "*****@*****.**", Status = Status.Unsubscribed }; member.MergeFields.Add("FNAME", "HOLY COW"); await _mailChimpManager.Members.AddOrUpdateAsync("72dcc9fa45", member); }
public async Task<Member> AddOrUpdateAsync(string listId, Member member) { using (var client = CreateMailClient("lists/")) { var response = await client.PutAsJsonAsync($"{listId}/members/{Hash(member.EmailAddress.ToLower())}", member, null); await response.EnsureSuccessMailChimpAsync(); return await response.Content.ReadAsAsync<Member>(); } }
public async Task Update_Existing_Member_From_List() { await AddNewMember(); var member = new Member { Status = Status.Subscribed, EmailAddress = $"{_ticks}@test.com" }; member.MergeFields.Add("FNAME", "HOLY COW"); var updateMember = await _mailChimpManager.Members.AddOrUpdateAsync("72dcc9fa45", member); }