Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

Get SpamAssassin Score for an Email

See more Email Object Examples

Uses Postmark’s spam API (a RESTfull interface to the SpamAssassin filter tool) to analyze an email to get a spam score.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
email: HCkEmail;
json: HCkJsonObject;
http: HCkHttp;
resp: HCkHttpResponse;

begin
success := False;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  First build an email to check.
email := CkEmail_Create();
CkEmail_putSubject(email,'this is a test');
CkEmail_putFrom(email,'support@chilkatsoft.com');
CkEmail_AddTo(email,'John Doe','john@example.com');
CkEmail_AddPlainTextAlternativeBody(email,'this is a test');
CkEmail_AddHtmlAlternativeBody(email,'<html><body><b>Hello John!</b><p>This is a test</p></body></html>');
success := CkEmail_AddFileAttachment2(email,'qa_data/jpg/starfish.jpg','image/jpeg');

//  Check this email by implementing this curl command:

//  curl -X POST "https://spamcheck.postmarkapp.com/filter"
//  -H "Accept: application/json"
//  -H "Content-Type: application/json"
//  -v
//  -d '{"email":"raw dump of email", "options":"short"}'

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'email',CkEmail__getMime(email));
CkJsonObject_UpdateString(json,'options','short');

http := CkHttp_Create();
resp := CkHttpResponse_Create();
success := CkHttp_HttpJson(http,'POST','https://spamcheck.postmarkapp.com/filter',json,'application/json',resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add('response status code = ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add('response body: ');
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));

CkEmail_Dispose(email);
CkJsonObject_Dispose(json);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);