Using Rack MailExceptions

143 views
Skip to first unread message

Trevor Turk

unread,
Mar 4, 2009, 4:19:01 PM3/4/09
to Rack Development
I've been fighting with the MailExceptions middleware here:

http://github.com/rack/rack-contrib/tree/master

...for a while. I can't seem to figure out how to use it, and I don't
see any tutorials in my googling.

Is anyone using this? Perhaps someone could provide a quick howto?

Thanks,
- Trevor

Ryan Tomayko

unread,
Mar 4, 2009, 11:26:16 PM3/4/09
to rack-...@googlegroups.com

I have some pretty large changes and docs planned but right now it
should be useable with:

require 'rack/contrib'

use Rack::MailExceptions do |mail|
mail.to 'f...@example.com'
mail.subject '[ERROR] %s'
end

run lambda { |env| fail 'boom!' }

Assuming you have an SMTP server running on localhost:25, this should
just work. Some additional notes:

* You can specify a "mail.from" address.

* The '%s' in the subject is replaced with the exception's message.

* Configure SMTP settings with: mail.smtp :server => '...', :user_name
=> '', :password => '...', etc. See
http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/mailexceptions.rb#L19
for a list of options.

* Only SMTP is currently supported. I plan to support using a local
mail(1) command at some point in the future.

* The MailExceptions middleware only works when exceptions are raised
up through the middleware chain. If your framework/app rescues
exceptions and turns them into error pages, you'll need to find a way
to disable that.

* All exceptions are re-raised after the mail is sent. Put
Rack::ShowExceptions (or something like it) before MailExceptions in
the middleware chain to get error pages.

Thanks,
Ryan

Trevor Turk

unread,
Mar 5, 2009, 12:56:31 PM3/5/09
to Rack Development
On Mar 4, 10:26 pm, Ryan Tomayko <r...@tomayko.com> wrote:
> Assuming you have an SMTP server running on localhost:25, this should
> just work. Some additional notes:
>
> * Only SMTP is currently supported. I plan to support using a local
> mail(1) command at some point in the future.
>
> * The MailExceptions middleware only works when exceptions are raised
> up through the middleware chain. If your framework/app rescues
> exceptions and turns them into error pages, you'll need to find a way
> to disable that.
>
> * All exceptions are re-raised after the mail is sent. Put
> Rack::ShowExceptions (or something like it) before MailExceptions in
> the middleware chain to get error pages.

Thanks very much for your response, Ryan. I was trying to use
MailExceptions as a replacement for the Exception Notifier in a Rails
app, but it sounds like that might have been a bad idea from jump
street. I think my middleware-fu is too weak.

In any case, I do appreciate the response. I'll post back here if I
can figure out how to pull this thing off :)

- Trevor
Reply all
Reply to author
Forward
0 new messages