Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Constant Contact V3: Send a test email to reviewers
See more Constant Contact Examples
Read the primary activity ID from newsletter-selection.json. Replace the two reviewer addresses and send a preview with a personal note. Only the specified reviewers receive it. The request leaves the campaign schedule and contact lists alone.
Use up to five addresses per request. Each recipient counts toward the 50 daily test emails. Contact personalization and custom field values are not expanded in test messages. Success is HTTP 204 with an empty body.
Authorize the application using the same account and credential store.
Constant Contact developer guide
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.Secrets,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
vault: TSecrets;
entry: TJsonObject;
tokens: TJsonObject;
loaded: Boolean;
http: THttp;
resp: THttpResponse;
selection: TJsonObject;
activityId: string;
testMail: TJsonObject;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
vault := TSecrets.Create;
vault.Location := 'local_manager';
vault.AutoSplit := True;
entry := TJsonObject.Create;
entry.UpdateString('appName','ConstantContactV3');
entry.UpdateString('service','OAuth2');
entry.UpdateString('username','my-account');
tokens := TJsonObject.Create;
loaded := vault.GetSecretJson(entry,tokens);
if (loaded <> True) then
begin
WriteLn('Run the desktop authorization example using this account and store.');
Exit;
end;
if (tokens.JsonTypeOf('access_token') <> 1) then
begin
WriteLn('The saved authorization has no access token.');
Exit;
end;
http := THttp.Create;
http.RequireSslCertVerify := True;
http.AuthToken := tokens.StringOf('access_token');
resp := THttpResponse.Create;
// Use the selection file from the draft or campaign lookup example for this account.
selection := TJsonObject.Create;
success := selection.LoadFile('newsletter-selection.json');
activityId := selection.StringOf('campaign_activity_id');
if ((success <> True) or (activityId = '')) then
begin
WriteLn('Select a campaign and save its primary activity ID first.');
Exit;
end;
http.SetUrlVar('activity',activityId);
testMail := TJsonObject.Create;
testMail.UpdateString('email_addresses[0]','editor@example.com');
testMail.UpdateString('email_addresses[1]','reviewer@example.com');
testMail.UpdateString('personal_message','Please check the workshop dates and the registration link.');
success := http.HttpJson('POST','https://api.cc.email/v3/emails/activities/{$activity}/tests',testMail,'application/json',resp);
if (resp.StatusCode = 429) then
begin
WriteLn('HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.');
Exit;
end;
if ((success <> True) and (resp.StatusCode <= 0)) then
begin
WriteLn('Send reviewer test: HTTP request failed.');
Exit;
end;
if ((success <> True) or (resp.StatusCode <> 204)) then
begin
WriteLn('Send reviewer test: HTTP ' + resp.StatusCode + ' ' + resp.BodyStr);
Exit;
end;
WriteLn('Test email accepted for the two reviewer addresses.');
vault.Free;
entry.Free;
tokens.Free;
http.Free;
resp.Free;
selection.Free;
testMail.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.