Ruby Requires Chilkat v11.0.0+
Ruby
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 Ruby Downloads
require 'chilkat'
success = false
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = Chilkat::CkEmail.new()
email.put_From("Workshop team <events@example.com>")
success = email.AddTo("Alex Rivera","alex@example.net")
if (success != true)
print email.lastErrorText() + "\n";
exit
end
email.put_Subject("Workshop registration")
email.put_Body("Your workshop registration is confirmed.")
request = Chilkat::CkJsonObject.new()
request.UpdateString("email",email.getMime())
request.UpdateString("options","short")
http = Chilkat::CkHttp.new()
http.put_RequireSslCertVerify(true)
resp = Chilkat::CkHttpResponse.new()
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 " + resp.get_StatusCode().to_s() + "\n";
exit
end
result = Chilkat::CkJsonObject.new()
success = result.Load(resp.bodyStr())
if (success != true)
print result.lastErrorText() + "\n";
exit
end
if (result.BoolOf("success") != true)
print result.stringOf("message") + "\n";
exit
end
print "SpamAssassin score: " + result.stringOf("score") + "\n";