Kamaelia docs : Kamaelia.Apps.Grey.GreyListingPolicy

Greylisting Policy For/Subclass Of Concrete Mail Handler

This component implements a greylisting SMTP proxy protocol, by subclassing ConcreteMailHandler and overriding the appropriate methods (primarily the shouldWeAcceptMail method).

For more detail, please see http://www.kamaelia.org/KamaeliaGrey

Example Usage

You use this as follows (at minimum):

ServerCore(protocol=GreyListingPolicy, port=25)

If you want to have a hardcoded/configured greylisting server you could do this:

class GreyLister(ServerCore):
    class protocol(GreyListingPolicy):
        allowed_senders = []
        allowed_sender_nets = []
        allowed_domains = [ ]


How does it work?

Primarily it override the method shouldWeAcceptMail, and implements the following logic:

if self.sentFromAllowedIPAddress():  return True # Allowed hosts can always send to anywhere through us
if self.sentFromAllowedNetwork():    return True # People on truste networks can always do the same
if self.sentToADomainWeForwardFor():
        for recipient in self.recipients:
            if self.whiteListed(recipient):
                return True
            if not self.isGreylisted(recipient):
                return False
    except Exception, e:
    return True # Anyone can always send to hosts we own

Clearly AllowedIPAddress, AllowedNetwork, whiteListed, and DomainWeForwardFor are fairly clear concepts, so for more details on those please look at the implementation.

isGreylisted by comparison is slightly more complex. Fundamentally this works on the basis of saying this:

  • have we seen the triple (ip, sender, recipient) before ?
  • if we have, then allow the message through
  • otherwise, defer the message

Now there is a little more subtlty here, based on the following conditions:

  • If greylisted, and not been there too long, allow through
  • If grey too long, refuse (restarting the greylisting for that combo)
  • If not seen this triplet before, defer and note triplet
  • If triplet retrying waaay too soon, reset their timer & defer
  • If triplet retrying too soon generally speaking just defer
  • If triplet hasn't been seen in aaaages, defer
  • Otherwise, allow through & greylist them


class GreyListingPolicy(Kamaelia.Apps.Grey.ConcreteMailHandler.ConcreteMailHandler)

Methods defined here


You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

Methods inherited from Kamaelia.Apps.Grey.ConcreteMailHandler.ConcreteMailHandler :

Methods inherited from Kamaelia.Apps.Grey.MailHandler.MailHandler :


Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT

Kamaelia is an open source project originated from and guided by BBC Research. For more information browse the site or get in contact.

This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)

(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.

This web site is powered by the same code created for the bicker manor project. For more details, contact Michael Sparks at BBC Research directly (cf contact)