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

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    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) {
        Log.i(TAG, 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) or (resp.get_StatusCode() != 200)) {
        Log.i(TAG, "SpamCheck request failed. HTTP " + String.valueOf(resp.get_StatusCode()));
        return;
        }

    CkJsonObject result = new CkJsonObject();
    success = result.Load(resp.bodyStr());
    if (success != true) {
        Log.i(TAG, result.lastErrorText());
        return;
        }

    if (result.BoolOf("success") != true) {
        Log.i(TAG, result.stringOf("message"));
        return;
        }

    Log.i(TAG, "SpamAssassin score: " + result.stringOf("score"));

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}