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

React Native
import { Email, Http, HttpResponse, JsonObject } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // First build an email to check.
  const email = new Email();
  email.subject = 'this is a test';
  email.from = '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"}'

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

  const http = new Http();
  const resp = new HttpResponse();
  try {
    await http.httpJsonAsync('POST', 'https://spamcheck.postmarkapp.com/filter', json, 'application/json', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`response status code = ${resp.statusCode}`);
  console.log('response body: ');
  console.log(resp.bodyStr);
}