Python Requires Chilkat v11.0.0+
Python
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 Python Downloads
import sys
import chilkat2
success = False
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = chilkat2.Email()
email.From = "Workshop team <events@example.com>"
success = email.AddTo("Alex Rivera","alex@example.net")
if (success != True):
print(email.LastErrorText)
sys.exit()
email.Subject = "Workshop registration"
email.Body = "Your workshop registration is confirmed."
request = chilkat2.JsonObject()
request.UpdateString("email",email.GetMime())
request.UpdateString("options","short")
http = chilkat2.Http()
http.RequireSslCertVerify = True
resp = chilkat2.HttpResponse()
success = http.HttpJson("POST","https://spamcheck.postmarkapp.com/filter",request,"application/json",resp)
if ((success != True) or (resp.StatusCode != 200)):
print("SpamCheck request failed. HTTP " + str(resp.StatusCode))
sys.exit()
result = chilkat2.JsonObject()
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"))