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

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

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

    CkEmail email = new CkEmail();
    email.put_From("Workshop team <events@example.com>");
    success = email.AddTo("Alex Rivera","alex@example.net");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    email.put_Subject("Workshop registration");
    email.put_Body("Your workshop registration is confirmed.");
    CkJsonObject request = new CkJsonObject();
    request.UpdateString("email",email.getMime());
    request.UpdateString("options","short");
    CkHttp http = new CkHttp();
    http.put_RequireSslCertVerify(true);
    CkHttpResponse resp = new CkHttpResponse();
    success = http.HttpJson("POST","https://spamcheck.postmarkapp.com/filter",request,"application/json",resp);
    if ((success != true) || (resp.get_StatusCode() != 200)) {
        System.out.println("SpamCheck request failed. HTTP " + resp.get_StatusCode());
        return;
        }

    CkJsonObject result = new CkJsonObject();
    success = result.Load(resp.bodyStr());
    if (success != true) {
        System.out.println(result.lastErrorText());
        return;
        }

    if (result.BoolOf("success") != true) {
        System.out.println(result.stringOf("message"));
        return;
        }

    System.out.println("SpamAssassin score: " + result.stringOf("score"));
  }
}