This module provides classes to check the SPF records of the sending client address.

class slimta.util.spf.EnforceSpf([timeout=10.0])

Bases: object

Class used to check SPF records and enforce a policy against the results. By default, results are logged but not acted upon.


timeout – Timeout in seconds before giving up the check. An SPF check that times out is equivalent to a 'temperror' result.

set_enforcement(result[, match_code='550'[, match_message='5.7.1 Access denied']])

Adds an enforcement policy to a particular SPF result. If the given result is seen, the MAIL FROM reply is set accordingly.

  • result – The result code, one of 'pass', 'permerror', 'fail', 'temperror', 'softfail', 'none', 'neutral'.

  • match_code – When the result code matches, set the Reply code to this string.

  • match_message – When the result code matches, set the Reply message to this string. You can use the {reason} template in your string.

query(sender, ip, ehlo_as)

Performs a direct query to check the sender’s domain to see if the given IP and EHLO string are authorized to send for that domain.

  • sender – The sender address.

  • ip – The IP address string of the sending client.

  • ehlo_as – The EHLO string given by the sending client.


A tuple of the result and reason strings.


Decorates SmtpValidators methods that are given a Reply object. It will check the current SMTP session’s connecting IP address and EHLO string against the given sender address. If enforcement policies are set for the result, the Reply is modified before calling the validator method.

This decorator can only be used on handle_mail(), handle_rcpt(), and handle_data().


f – The overloaded SmtpValidators method to decorate.