Table of Contents

Managing members

Members are the subscribers within an audience. TTMSFNCCloudMailChimpMarketing adds, updates, archives, and deletes members, and reads them back a page at a time so large audiences stay manageable. This chapter covers adding a member, paging through the member list, and the member status values.

Adding members

Build a TTMSFNCCloudMailChimpListMember, set its EmailAddress, EmailType (usually 'html'), and Status, then call AddMember with the target audience's Id. The result arrives in OnAddMember. Update an existing member with UpdateMember, archive one with ArchiveMember, and remove one with DeleteMember — each reporting through its own event.

procedure TForm1.AddMember(AList: TTMSFNCCloudMailChimpSubscriberList; const AEmail: string);
var
  Member: TTMSFNCCloudMailChimpListMember;
begin
  Member := TTMSFNCCloudMailChimpListMember.Create;
  Member.EmailAddress := AEmail;
  Member.EmailType := 'html';
  Member.Status := TTMSFNCCloudMailChimpListMemberStatus.msSubscribed;
  FMailChimp.AddMember(AList.Id, Member); // result arrives in OnAddMember
end;

procedure TForm1.MailChimpGetMembers(Sender: TObject;
  AMembers: TTMSFNCCloudMailChimpListMembers);
var
  Member: TTMSFNCCloudMailChimpListMember;
begin
  ListBox2.Clear;
  for Member in AMembers do
    ListBox2.Items.AddObject(Member.EmailAddress, Member);
end;

procedure TForm1.LoadFirstMembers(AList: TTMSFNCCloudMailChimpSubscriberList);
begin
  FMailChimp.GetFirstMembers(AList); // then GetNextMembers / GetPreviousMembers to page
end;

procedure TForm1.ShowNextMemberPage(AList: TTMSFNCCloudMailChimpSubscriberList);
begin
  FMailChimp.GetNextMembers(AList); // each page arrives in OnGetMembers
end;

Paging through members

Audiences can hold many subscribers, so members are fetched in pages. Start with GetFirstMembers(AList), then move with GetNextMembers and GetPreviousMembers, or reload the current page with GetCurrentMembers. Every page arrives in the same OnGetMembers event, so refresh your display there.

Member status

A member's Status is a TTMSFNCCloudMailChimpListMemberStatus; common values are msSubscribed (active), msUnsubscribed, msCleaned (bounced), and msPending (awaiting opt-in confirmation). Set it when adding a member and read it to show subscription state.

Pitfalls

  • Pass the audience Id to AddMember, not the audience object — the call expects the list identifier as its first argument.
  • Act in the completion event. The member collection is only guaranteed after OnGetMembers/OnAddMember fires.
  • Respect double opt-in. Adding a member as msPending triggers Mailchimp's confirmation email rather than an immediate subscription.

See also