TMail and spam filtering

I’ve been musing over the past day or so on how best to assess whether our mailers are sending out messages that are likely to get caught by over zealous spam filters and render our e-mail campaigns useless.

One possible is to run all outbound e-mails through spam assassin, so for standard mailers we can just add a spec to check the content and for form mailers we can use it during validation before the final send off.

class TMail::Mail

  def spam?
    spam_filtered_body = %x[ echo '#{self.encoded}' | /usr/bin/spamassassin ]
    return !! spam_filtered_body.match(/X-Spam-Status:\sYes/)
  end

end