Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Variant vJson
    Handle hoJson
    Handle hoHttp
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    // First build an email to check.
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "this is a test"
    Set ComFrom Of hoEmail To "support@chilkatsoft.com"
    Get ComAddTo Of hoEmail "John Doe" "john@example.com" To iSuccess
    Get ComAddPlainTextAlternativeBody Of hoEmail "this is a test" To iSuccess
    Get ComAddHtmlAlternativeBody Of hoEmail "<html><body><b>Hello John!</b><p>This is a test</p></body></html>" To iSuccess
    Get ComAddFileAttachment2 Of hoEmail "qa_data/jpg/starfish.jpg" "image/jpeg" To iSuccess

    // 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"}'

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComGetMime Of hoEmail To sTemp1
    Get ComUpdateString Of hoJson "email" sTemp1 To iSuccess
    Get ComUpdateString Of hoJson "options" "short" To iSuccess

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoResp to vResp
    Get ComHttpJson Of hoHttp "POST" "https://spamcheck.postmarkapp.com/filter" vJson "application/json" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "response status code = " iTemp1
    Showln "response body: "
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1


End_Procedure