Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Request a SpamAssassin score for a sample email
See more Email Object Examples
Submit a synthetic message to Postmark’s SpamCheck endpoint. The service receives the complete MIME you provide. Request a short result and check both the HTTP status and the API success field before reading the numeric score. SpamCheck API documentation.
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.Email,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
request: TJsonObject;
http: THttp;
resp: THttpResponse;
result: TJsonObject;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
email.From := 'Workshop team <events@example.com>';
success := email.AddTo('Alex Rivera','alex@example.net');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
email.Subject := 'Workshop registration';
email.Body := 'Your workshop registration is confirmed.';
request := TJsonObject.Create;
request.UpdateString('email',email.GetMime());
request.UpdateString('options','short');
http := THttp.Create;
http.RequireSslCertVerify := True;
resp := THttpResponse.Create;
success := http.HttpJson('POST','https://spamcheck.postmarkapp.com/filter',request,'application/json',resp);
if ((success <> True) or (resp.StatusCode <> 200)) then
begin
WriteLn('SpamCheck request failed. HTTP ' + resp.StatusCode);
Exit;
end;
result := TJsonObject.Create;
success := result.Load(resp.BodyStr);
if (success <> True) then
begin
WriteLn(result.LastErrorText);
Exit;
end;
if (result.BoolOf('success') <> True) then
begin
WriteLn(result.StringOf('message'));
Exit;
end;
WriteLn('SpamAssassin score: ' + result.StringOf('score'));
email.Free;
request.Free;
http.Free;
resp.Free;
result.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.