This project is read-only.

Using Orchard Anti-Spam in my Module

Topics: Writing modules
Jan 9, 2013 at 10:22 PM
Edited Jan 10, 2013 at 1:37 AM

I'm writing a basic contact form module ( We want spam protection on the form. At first we modeled it very much on what the Orchard.Comments module was doing, which is using an Akismet .Net library directly.

It has occurred to me that it would be better if I could leverage Orchard.AntiSpam. So I refactored a local copy to inject the ISpamService from that module, and then use its CheckForSpam implementation.

I wanted to run this approach through this discussion board. Since I have the Orchard.AntiSpam listed as a dependency, my new approach seems better (for example, the service works with multiple spam services, not just Akismet), however it worries me that the Orchard.Comments isn't doing this.

Does anyone know of why Orchard.Comments is using an Akismet API directly, or more to the point, any reason we can't just inject ISpamService and use it?

P.S. As an aside, does anyone know a good way to test this in dev? I don't want my email flagged on Akismet or anything, but it just feels weird to write code that can't really be tested until deployed to the wild.

Jan 10, 2013 at 1:22 AM

The comments module has been refactored since you looked. It now uses the same anti-spam.

Jan 10, 2013 at 1:35 AM

So injecting the ISpamService is definitely the way to go. I'll get this update in soon, look for this sweet simple contact form in the gallery soon!

Jan 10, 2013 at 1:41 AM


Jun 29, 2013 at 8:26 PM
Hi Bertrand,

The changes to Orchard.AntiSpam in the 1.x branch have broken this module. It was originally passing:
        private bool MessageIsSpam(string email, string message)
            if (_spamService.CheckForSpam(message, SpamFilterAction.One) == SpamStatus.Spam)
                Logger.Information("A contact form submission from email address " + email + " was flagged as spam.");
                return true;

            return false;
but Orchard.AntiSpam is now looking for a SpamFilterPart to be passed to the CheckForSpam method.

Can you or anyone else point me to somewhere in 1.x for an example of using the new implementation (if one exists yet)...I was hoping to help the author of this module with a proposed code change for when 1.7 is released. I looked through Orchard.Comments, but didn't see anything relating to AntiSpam.

Thanks for any pointers you can give =)