Perl Requires Chilkat v11.0.0+
Perl
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 Perl Downloads
use strict;
use warnings;
use Chilkat2;
# Assumes Chilkat is unlocked. See Global Unlock Sample.
my $email = Chilkat2::Email->new;
$email->From('Workshop team <events@example.com>');
my $success = $email->AddTo('Alex Rivera', 'alex@example.net');
if (!$success) {
print $email->LastErrorText, "\n";
exit;
}
$email->Subject('Workshop registration');
$email->Body('Your workshop registration is confirmed.');
my $request = Chilkat2::JsonObject->new;
$request->UpdateString('email', $email->GetMime());
$request->UpdateString('options', 'short');
my $http = Chilkat2::Http->new;
$http->RequireSslCertVerify(1);
my $resp = Chilkat2::HttpResponse->new;
$success = $http->HttpJson('POST', 'https://spamcheck.postmarkapp.com/filter', $request, 'application/json', $resp);
if ((!$success) || ($resp->StatusCode != 200)) {
print 'SpamCheck request failed. HTTP ', $resp->StatusCode, "\n";
exit;
}
my $result = Chilkat2::JsonObject->new;
$success = $result->Load($resp->BodyStr);
if (!$success) {
print $result->LastErrorText, "\n";
exit;
}
if (!$result->BoolOf('success')) {
print $result->StringOf('message'), "\n";
exit;
}
print 'SpamAssassin score: ', $result->StringOf('score'), "\n";