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

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

void main() {
  var success = false;

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

  final email = CkEmail();
  email.from = 'Workshop team <events@example.com>';
  try {
    email.addTo('Alex Rivera', 'alex@example.net');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  email.subject = 'Workshop registration';
  email.body = 'Your workshop registration is confirmed.';
  final request = CkJsonObject();
  request.updateString('email', email.getMime());
  request.updateString('options', 'short');
  final http = CkHttp();
  http.requireSslCertVerify = true;
  final resp = CkHttpResponse();
  success = true;
  try {
    http.httpJson('POST', 'https://spamcheck.postmarkapp.com/filter', request, 'application/json', resp);
  } on ChilkatException {
    success = false;
  }
  if ((!success) || (resp.statusCode != 200)) {
    print('SpamCheck request failed. HTTP ${resp.statusCode}');
    return;
  }

  final result = CkJsonObject();
  try {
    result.load(resp.bodyStr);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  if (!result.boolOf('success')) {
    print(result.stringOf('message'));
    return;
  }

  print('SpamAssassin score: ${result.stringOf('score')}');
}