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

Dart
import 'package:chilkat/chilkat.dart';

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

  // First build an email to check.
  final email = CkEmail();
  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"}'

  final json = CkJsonObject();
  json.updateString('email', email.getMime());
  json.updateString('options', 'short');

  final http = CkHttp();
  final resp = CkHttpResponse();
  try {
    http.httpJson('POST', 'https://spamcheck.postmarkapp.com/filter', json, 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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