Rust Requires Chilkat v11.0.0+
Rust
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 Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First build an email to check.
let email = chilkat::Email::new();
email.set_subject("this is a test");
email.set_from("support@chilkatsoft.com");
let _ = email.add_to("John Doe", "john@example.com");
let _ = email.add_plain_text_alternative_body("this is a test");
let _ = email.add_html_alternative_body("<html><body><b>Hello John!</b><p>This is a test</p></body></html>");
let _ = email.add_file_attachment2("qa_data/jpg/starfish.jpg", "image/jpeg").is_ok();
// 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"}'
let json = chilkat::JsonObject::new();
let _ = json.update_string("email", &email.get_mime().unwrap_or_default());
let _ = json.update_string("options", "short");
let http = chilkat::Http::new();
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://spamcheck.postmarkapp.com/filter", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("response status code = {}", resp.status_code());
println!("response body: ");
println!("{}", resp.body_str());