Implements an Edge that receives messages with the HTTP protocol. WSGI is a Python specification for defining communication between web servers and the application.

The resulting edge can be used by any HTTP client, like curl:

$ curl -v -X POST -H 'Content-Type: message/rfc822' \
       --data-binary @test.eml \
       -H 'X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t' \
       -H 'X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t' \
* About to connect() to localhost port 8080 (#0)
*   Trying
* Connected to localhost ( port 8080 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> Content-Type: message/rfc822
> X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t
> X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t
> Content-Length: 99
* upload completely sent off: 99 out of 99 bytes
< HTTP/1.1 200 OK
< X-Smtp-Reply: 250; message="2.6.0 Message accepted for delivery"
< Date: Mon, 29 Jul 2013 20:11:55 GMT
< Content-Length: 0
* Connection #0 to host localhost left intact
exception slimta.edge.wsgi.WsgiResponse(status[, headers=None[, data=None]])

Bases: Exception

This exception can be explicitly raised to end the WSGI request and return the given response.

  • status – The HTTP status string to return, e.g. 200 OK.
  • headers – List of (name, value) header tuples to return.
  • data – Optional raw data string to return.
class slimta.edge.wsgi.WsgiEdge(queue[, hostname=None[, validator_class=None[, uri_pattern=None[, listener=None[, pool=None[, context=None]]]]]])

Bases: slimta.edge.EdgeServer, slimta.http.wsgi.WsgiServer

This class is intended to be instantiated and used as an app on top of a WSGI server engine such as gevent.pywsgi.WSGIServer. It will only acccept POST requests that provide a message/rfc822 payload.


If listener is not provided, use build_server() to build and manage the server manually.

  • queueQueue object used by handoff() to ensure the envelope is properly queued before acknowledged by the edge service.
  • hostname – String identifying the local machine. See Edge for more details.
  • validator_class – A class inherited from WsgiValidators whose methods will be executed on various request headers to validate the request.
  • uri_pattern (RegexObject or str) – If given, only URI paths that match the given pattern will be allowed.
  • listener – Usually a (ip, port) tuple defining the interface and port upon which to listen for connections.
  • pool – If given, defines a specific gevent.pool.Pool to use for new greenlets.
  • context (SSLContext) – Enables SSL encryption on connected sockets using the information given in the context.
http_verb = 'POST'

The HTTP verb that clients will use with the requests. This may be changed with caution.

sender_header = 'X-Envelope-Sender'

The header name that clients will use to provide the envelope sender address.

rcpt_header = 'X-Envelope-Recipient'

The header name that clients will use to provide the envelope recipient addresses. This header may be given multiple times, for each recipient.

ehlo_header = 'X-Ehlo'

The header name that clients will use to provide the EHLO identifier string, as in an SMTP session.

class slimta.edge.wsgi.WsgiValidators(environ)

Bases: object

Base class for implementing WSGI request validation. Instances will be created for each WSGI request.

To terminate the current WSGI request with a response, raise the WsgiResponse exception from with the validator methods.

Parameters:environ – The environment variables for the current session.
custom_headers = []

A static list of headers that should be passed in to validate_custom().

environ = None

Stores the environment variables for the current session.


Override this method to validate the EHLO string passed in by the client in the X-Ehlo (or equivalent) header.

Parameters:ehlo – The value of the EHLO header.

Override this method to validate the sender address passed in by the client in the X-Envelope-Sender (or equivalent) header.

Parameters:sender – The decoded value of the sender header.

Override this method to validate each recipient address passed in by the client in the X-Envelope-Recipient (or equivalent) headers. This method will be called for each occurence of the header.

Parameters:recipient – The decoded value of one recipient header.
validate_custom(name, value)

Override this method to validate custom headers sent in by the client. This method will be called exactly once for each header listed in the custom_headers class attribute.

  • name – The name of the header.
  • value – The raw value of the header, or None if the client did not provide the header.