Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        // First build an email to check.
        Email email = new Email();
        email.setSubject("this is a test");
        email.setFrom("support@chilkatsoft.com");
        email.addTo("John Doe", "john@example.com");
        email.addPlainTextAlternativeBody("this is a test");
        email.addHtmlAlternativeBody("<html><body><b>Hello John!</b><p>This is a test</p></body></html>");
        email.addFileAttachment2("qa_data/jpg/starfish.jpg", "image/jpeg");

        // 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"}'

        JsonObject json = new JsonObject();
        json.updateString("email", email.getMime());
        json.updateString("options", "short");

        Http http = new Http();
        HttpResponse resp = new HttpResponse();
        try {
            http.httpJson("POST", "https://spamcheck.postmarkapp.com/filter", json, "application/json", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("response status code = " + resp.getStatusCode());
        System.out.println("response body: ");
        System.out.println(resp.getBodyStr());
    }
}