Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL oJson
LOCAL oHttp
LOCAL oResp

nSuccess := 0

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

//  First build an email to check.
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "this is a test"
oEmail:From := "support@chilkatsoft.com"
oEmail:AddTo("John Doe", "john@example.com")
oEmail:AddPlainTextAlternativeBody("this is a test")
oEmail:AddHtmlAlternativeBody("<html><body><b>Hello John!</b><p>This is a test</p></body></html>")
nSuccess := oEmail:AddFileAttachment2("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"}'

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("email", oEmail:GetMime())
oJson:UpdateString("options", "short")

oHttp := CreateObject("Chilkat.Http")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://spamcheck.postmarkapp.com/filter", oJson, "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oEmail:destroy()
    oJson:destroy()
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "response status code = " + Str(oResp:StatusCode)
? "response body: "
? oResp:BodyStr

oEmail:destroy()
oJson:destroy()
oHttp:destroy()
oResp:destroy()