Table of Contents

Managing campaigns

A campaign is an email sent to an audience. TTMSFNCCloudMailChimpMarketing creates campaigns, sets their content, lists them, and sends them — the full publish cycle. This chapter covers creating a campaign for an audience, filling its content, and sending it, then listing existing campaigns.

Creating campaigns

Build a TTMSFNCCloudMailChimpCampaign, choose its CampaignType (e.g. ctRegular), point ListID at the target audience's Id, and fill the Settings sub-object (Title, SubjectLine, FromName, ReplyTo, PreviewText, Authenticate). Call AddCampaign; the result arrives in OnAddCampaign. Update settings later with UpdateCampaign and remove a campaign with DeleteCampaign.

Setting content and sending

A new campaign has no body until you give it one. Call SetCampaignContent with the campaign and its HTML; read it back with GetCampaignContent, which returns both the HTML and a plain-text rendering in OnGetCampaignContent. When the content is ready, SendCampaign delivers it to the audience and OnSendCampaign confirms the send. This example ties an audience to a new campaign, fills it, and sends it.

procedure TForm1.CreateCampaign(AList: TTMSFNCCloudMailChimpSubscriberList);
var
  C: TTMSFNCCloudMailChimpCampaign;
begin
  C := TTMSFNCCloudMailChimpCampaign.Create;
  C.CampaignType := ctRegular;
  C.ListID := AList.Id; // ties the campaign to an audience
  C.Settings.Title := 'June newsletter';
  C.Settings.SubjectLine := 'What''s new in June';
  C.Settings.FromName := 'Contoso News';
  C.Settings.ReplyTo := 'news@contoso.com';
  C.Settings.PreviewText := 'Your monthly update';
  C.Settings.Authenticate := True;
  FMailChimp.AddCampaign(C); // result arrives in OnAddCampaign
end;

procedure TForm1.FillCampaignContent(ACampaign: TTMSFNCCloudMailChimpCampaign; const AHtml: string);
begin
  FMailChimp.SetCampaignContent(ACampaign, AHtml); // result arrives in OnSetCampaignContent
end;

procedure TForm1.Send(ACampaign: TTMSFNCCloudMailChimpCampaign);
begin
  FMailChimp.SendCampaign(ACampaign); // result arrives in OnSendCampaign
end;

procedure TForm1.MailChimpGetCampaigns(Sender: TObject;
  ACampaigns: TTMSFNCCloudMailChimpCampaigns);
var
  C: TTMSFNCCloudMailChimpCampaign;
begin
  ListBox1.Clear;
  for C in ACampaigns do
    ListBox1.Items.AddObject(C.Settings.Title, C);
end;

Listing campaigns

Call GetCampaigns(AOffset, AList) to load the campaigns of an audience; they arrive in OnGetCampaigns. Each TTMSFNCCloudMailChimpCampaign exposes its Settings and a Status string (such as save, schedule, or sent) so you can show where each campaign stands.

Pitfalls

  • Set content before sending. A campaign with no body cannot be sent; call SetCampaignContent first.
  • Point ListID at a real audience Id. A campaign without a valid audience is rejected (surfacing through OnError).
  • Sending is final. SendCampaign delivers immediately to the audience; there is no undo.

See also