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

Lua
local chilkat = require("chilkat")

-- Assumes Chilkat is unlocked. See Global Unlock Sample.

local email = chilkat.Email.new()
email.from = "Workshop team <events@example.com>"
local success = email:add_to("Alex Rivera", "alex@example.net")
if not success then
    print(email.last_error_text)
    return
end

email.subject = "Workshop registration"
email.body = "Your workshop registration is confirmed."
local request = chilkat.JsonObject.new()
request:update_string("email", email:get_mime())
request:update_string("options", "short")
local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://spamcheck.postmarkapp.com/filter", request, "application/json", resp)
if (not success) or (resp.status_code ~= 200) then
    print("SpamCheck request failed. HTTP " .. resp.status_code)
    return
end

local result = chilkat.JsonObject.new()
success = result:load(resp.body_str)
if not success then
    print(result.last_error_text)
    return
end

if not result:bool_of("success") then
    print(result:string_of("message"))
    return
end

print("SpamAssassin score: " .. result:string_of("score"))