Need to scan email contents for spam before sending to users
-
03-06-2021 - |
Question
I have a PHP application which is used by clients to send emails to their customers. There is a page that lets client user build email templates to send to their customers.
I want to add a functionality called 'Spam check'. This will allow client users to check their email template pass spam filter or not.
I have spamassassin installed on the server. How do I use it to check spam contents in the email template before it is sent to the customers ?
Solution
Solution 1
You can use Bayesian Spam Filter http://en.wikipedia.org/wiki/Bayesian_spam_filtering
For Background Knowledge
Bayesian probability : http://en.wikipedia.org/wiki/Bayesian_probability
Bayesian inference : http://en.wikipedia.org/wiki/Bayesian_inference
PHP
Implementation It has been discussed here several times
Combining individual probabilities in Naive Bayesian spam filtering
Solution 2
Since you have spamassassin installed
on your system you can
$fname = tempnam ( "/tmp", "sa" );
file_put_contents ( $fname, $message ); // Put the template in a file
/* Execute the system command and pass the file name to get spam count */
exec ( "/usr/bin/spamc -R < $fname", $score, $rr );
/* This will return score details in array format */
print_r ( $score );
You can now manipulate the score for spam filter