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

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    success.i = 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.
    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::setCkSubject(email, "this is a test")
    CkEmail::setCkFrom(email, "support@chilkatsoft.com")
    CkEmail::ckAddTo(email,"John Doe","john@example.com")
    CkEmail::ckAddPlainTextAlternativeBody(email,"this is a test")
    CkEmail::ckAddHtmlAlternativeBody(email,"<html><body><b>Hello John!</b><p>This is a test</p></body></html>")
    success = CkEmail::ckAddFileAttachment2(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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"email",CkEmail::ckGetMime(email))
    CkJsonObject::ckUpdateString(json,"options","short")

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpJson(http,"POST","https://spamcheck.postmarkapp.com/filter",json,"application/json",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkEmail::ckDispose(email)
        CkJsonObject::ckDispose(json)
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    Debug "response status code = " + Str(CkHttpResponse::ckStatusCode(resp))
    Debug "response body: "
    Debug CkHttpResponse::ckBodyStr(resp)


    CkEmail::ckDispose(email)
    CkJsonObject::ckDispose(json)
    CkHttp::ckDispose(http)
    CkHttpResponse::ckDispose(resp)


    ProcedureReturn
EndProcedure