Skip to content

Commit

Permalink
Document the middleware feature
Browse files Browse the repository at this point in the history
  • Loading branch information
loopj committed Aug 11, 2013
1 parent fa27261 commit 699ba96
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,29 @@ interfere with running Mailman with cron or as a daemon.
(Control-C) and allow the mail receiver to finish its current
iteration before exiting. Note that this currently only works
with POP3 receivers.

### Middleware

`Mailman.config.middleware` gives you access to the Mailman middleware stack.
Middleware allows you to execute code before and after each message is
processed. Middleware is super useful for things like error handling and any
other actions you need to do before/after each message is processed.

Here's an example of some simple error logging middleware:

```ruby
# Define the middleware
class ErrorLoggingMiddleware
def call(mail)
begin
yield
rescue
puts "There was an error processing this message! #{mail.subject}"
raise
end
end
end

# Add it to the Mailman middleware stack
Mailman.config.middleware.add ErrorLoggingMiddleware
```

0 comments on commit 699ba96

Please sign in to comment.