0

I am working on an application that lets users build email campaigns to distribute en masse (following all good non-spam practices, of course). We want to put some kind of scoring system in there to get onto them if they put in key things, like "Money back guarantee" or "free viagra", all caps subject lines, etc.

After doing tons of research, it looks like it would be great to just send their email content to SpamAssassin, get a score, and return that to them. I could just write my own spam detection, but it couldn't compete with SA.

Problem is, I can't figure out how to use php to talk to SA. Can't I just hand it some html and get a number and some warnings back? Is there any other open source solution to this?

Captain Hypertext
  • 2,446
  • 4
  • 27
  • 36
  • I highly recommend Googling `spamassassin api` and eventually finding https://bitbucket.org/coldclimate/postmarkspamapi_codeigniter/src/ac7e82e71e1be71bfe91616d799f6a0f7f9c1124/Postmark_spam.php?at=default – MonkeyZeus Aug 25 '15 at 20:04

1 Answers1

1

Probably too simple in implementation, but probably something like this would be a start:

<?php

$sa_program = "/usr/local/bin/spamassassin"; //your path to the executable
$mail_message = "/tmp/mail_message";         //file on server

exec("$sa_program < $mail_message", $output, $return);

if (!$return) { // "0" is success in 'Nix
    if (strstr(implode("\n",$output),"X-Spam-Flag: YES")) {
       //it's spam, according to SA
    } else {
       //it's not
    }
}

I don't know if you could feed it a string variable instead of a file on disk.

Also keep in mind I've not checked the score ... you might want to do that, too ("X-Spam-Status: Yes, score=5.0" --- keep in mind "No" as a possible value there).

Note that it's a great tool, but SpamAssassin configuration and operation is not for the timid. Unless you've spent a TON of work training it, both on spam and Ham, it's hard to trust its Bayes filter ... hard for me at least.

Hope this helps.

Kevin_Kinsey
  • 2,285
  • 1
  • 22
  • 23
  • Great suggestion, this gives me a good start. Guess I really thought SA would be more php friendly :/ – Captain Hypertext Aug 26 '15 at 12:18
  • It's a Perl script, actually. You might take a look at the suggestion above in the comments; I've no idea about it, myself, but a simple API you can query via HTTP might be fairly easy to implement. The downside might be that the service isn't fully controlled by you like a local SA installation would be. – Kevin_Kinsey Aug 26 '15 at 15:16