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

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

CkPython
import sys
import chilkat

success = False

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

email = chilkat.CkEmail()
email.put_From("Workshop team <events@example.com>")
success = email.AddTo("Alex Rivera","alex@example.net")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

email.put_Subject("Workshop registration")
email.put_Body("Your workshop registration is confirmed.")
request = chilkat.CkJsonObject()
request.UpdateString("email",email.getMime())
request.UpdateString("options","short")
http = chilkat.CkHttp()
http.put_RequireSslCertVerify(True)
resp = chilkat.CkHttpResponse()
success = http.HttpJson("POST","https://spamcheck.postmarkapp.com/filter",request,"application/json",resp)
if ((success != True) or (resp.get_StatusCode() != 200)):
    print("SpamCheck request failed. HTTP " + str(resp.get_StatusCode()))
    sys.exit()

result = chilkat.CkJsonObject()
success = result.Load(resp.bodyStr())
if (success != True):
    print(result.lastErrorText())
    sys.exit()

if (result.BoolOf("success") != True):
    print(result.stringOf("message"))
    sys.exit()

print("SpamAssassin score: " + result.stringOf("score"))