Zig Requires Chilkat v11.0.0+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// 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 = try chilkat.Email.init();
defer email.deinit();
email.setSubject("this is a test");
email.setFrom("support@chilkatsoft.com");
email.addTo("John Doe", "john@example.com") catch {};
email.addPlainTextAlternativeBody("this is a test") catch {};
email.addHtmlAlternativeBody("<html><body><b>Hello John!</b><p>This is a test</p></body></html>") catch {};
try 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 = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("email", try email.getMime(alloc)) catch {};
json.updateString("options", "short") catch {};
const http = try chilkat.Http.init();
defer http.deinit();
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://spamcheck.postmarkapp.com/filter", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("response status code = {d}\n", .{resp.getStatusCode()});
std.debug.print("response body: \n", .{});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
}