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

Lua
local chilkat = require("chilkat")

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

-- First build an email to check.
local email = chilkat.Email.new()
email.subject = "this is a test"
email.from = "support@chilkatsoft.com"
email:add_to("John Doe", "john@example.com")
email:add_plain_text_alternative_body("this is a test")
email:add_html_alternative_body("<html><body><b>Hello John!</b><p>This is a test</p></body></html>")
local success = email:add_file_attachment2("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"}'

local json = chilkat.JsonObject.new()
json:update_string("email", email:get_mime())
json:update_string("options", "short")

local http = chilkat.Http.new()
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://spamcheck.postmarkapp.com/filter", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

print("response status code = " .. resp.status_code)
print("response body: ")
print(resp.body_str)