Objective-C Requires Chilkat v11.0.0+
Objective-C
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 Objective-C Downloads
#import <CkoEmail.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoEmail *email = [[CkoEmail alloc] init];
email.From = @"Workshop team <events@example.com>";
success = [email AddTo: @"Alex Rivera" emailAddress: @"alex@example.net"];
if (success != YES) {
NSLog(@"%@",email.LastErrorText);
return;
}
email.Subject = @"Workshop registration";
email.Body = @"Your workshop registration is confirmed.";
CkoJsonObject *request = [[CkoJsonObject alloc] init];
[request UpdateString: @"email" value: [email GetMime]];
[request UpdateString: @"options" value: @"short"];
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpJson: @"POST" url: @"https://spamcheck.postmarkapp.com/filter" json: request contentType: @"application/json" response: resp];
if ((success != YES) || ([resp.StatusCode intValue] != 200)) {
NSLog(@"%@%d",@"SpamCheck request failed. HTTP ",[resp.StatusCode intValue]);
return;
}
CkoJsonObject *result = [[CkoJsonObject alloc] init];
success = [result Load: resp.BodyStr];
if (success != YES) {
NSLog(@"%@",result.LastErrorText);
return;
}
if ([result BoolOf: @"success"] != YES) {
NSLog(@"%@",[result StringOf: @"message"]);
return;
}
NSLog(@"%@%@",@"SpamAssassin score: ",[result StringOf: @"score"]);