C
C
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 C Downloads
#include <C_CkEmail.h>
#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmail email;
HCkJsonObject json;
HCkHttp http;
HCkHttpResponse resp;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First build an email to check.
email = CkEmail_Create();
CkEmail_putSubject(email,"this is a test");
CkEmail_putFrom(email,"support@chilkatsoft.com");
CkEmail_AddTo(email,"John Doe","john@example.com");
CkEmail_AddPlainTextAlternativeBody(email,"this is a test");
CkEmail_AddHtmlAlternativeBody(email,"<html><body><b>Hello John!</b><p>This is a test</p></body></html>");
success = CkEmail_AddFileAttachment2(email,"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"}'
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"email",CkEmail_getMime(email));
CkJsonObject_UpdateString(json,"options","short");
http = CkHttp_Create();
resp = CkHttpResponse_Create();
success = CkHttp_HttpJson(http,"POST","https://spamcheck.postmarkapp.com/filter",json,"application/json",resp);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkEmail_Dispose(email);
CkJsonObject_Dispose(json);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
return;
}
printf("response status code = %d\n",CkHttpResponse_getStatusCode(resp));
printf("response body: \n");
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkEmail_Dispose(email);
CkJsonObject_Dispose(json);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
}