Swift Requires Chilkat v11.0.0+
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let email = CkoEmail()!
email.from = "Workshop team <events@example.com>"
success = email.add(to: "Alex Rivera", emailAddress: "alex@example.net")
if success != true {
print("\(email.lastErrorText!)")
return
}
email.subject = "Workshop registration"
email.body = "Your workshop registration is confirmed."
let request = CkoJsonObject()!
request.updateString(jsonPath: "email", value: email.getMime())
request.updateString(jsonPath: "options", value: "short")
let http = CkoHttp()!
http.requireSslCertVerify = true
let resp = CkoHttpResponse()!
success = http.httpJson(verb: "POST", url: "https://spamcheck.postmarkapp.com/filter", json: request, contentType: "application/json", response: resp)
if (success != true) || (resp.statusCode.intValue != 200) {
print("SpamCheck request failed. HTTP \(resp.statusCode.intValue)")
return
}
let result = CkoJsonObject()!
success = result.load(json: resp.bodyStr)
if success != true {
print("\(result.lastErrorText!)")
return
}
if result.bool(of: "success") != true {
print("\(result.string(of: "message")!)")
return
}
print("SpamAssassin score: \(result.string(of: "score")!)")
}