Demo Popup Emails?

I'm wondering if anyone can suggest a feature/mechanism for me? I'm building a web app and want to simulate the email system in some reasonable way so that the system can be run in "demo mode" if you will.

My thought was to build out the email capability but instead of delivering emails, they would appear in a pop-up window, so the user would see what the email would contain but no actual emails are sent.

Ideally, I would add this "demo mode" completely independent of the actual code and maybe called due to some environment variable... a "demo=true" type flag. Then, it would intercept the email content and generate a popup window.

Is there anything like this? Or any ideas how to go about doing this? I thing my biggest unknown is how to take the email content and force a pop-up regardless of what the rest of the app is doing (normal request/response, ajax, renders/redirects, whatever).

Thanks for any suggestions!


do you really need this in a way, that users can see the results or is it mainly for people who will test the app? ActionMailer can be easily configured, not to deliver the mail and show the results in developmen.log instead. for our testing this was always enough.

otherwise the ActionMailer templates are erb files, you can use them wherever you like, just define the necessary variables before rendering them

so where for ActionMailer you need to do this: @body = { :name => params[:name], :text => params[:text] }

you would @name = params[:name] @text = params[:text] and render :template => "path/to/actionmailer/template"

i think on that line it should be easy


Thanks for the quick reply.

Yeah, I need it for people trying out (i.e. demoing) the app. For example, as a quick case, when a new user signs up, the live app would email them a signup welcome email including an activation code. When the app is in demo mode, I want that email with activation code to simply display, ideally in a pop-up, so the user trying out the demo will be able to both see the email contents and interact with it to continue the demo (i.e. click the activation link from within the popup).

I understand how I can grab the actionmailer variables and template to build the content for the popup. I'm not sure how I can hook this in, though, and create the popup. The less-than-desirable way would be to handle it within the controller that generates the email. What I really want is to have this completely transparent to the application itself. I.e. it just creates the emails and sends them as normal, but through some means, maybe even defining a new "delivery mechanism" within the environment.rb, the code would create (or update) a pop-up.

Maybe my main question, then, is how to generate or intercept the request/response chain and create a popup with content that is separate from the normal app flow?

Well, one half of this was incredibly easy. Monkeypatch ActionMailer::Base and add "perform_delivery_demo(mail)" as a method. Then set the delivery_method in development.rb to :demo

But now the hard part. So I've got my custom method. I can get at the mail content. But apparently I have to hook to something that would let me send or create or update an HTTP request back to the browser. This is beyond my Rails knowledge. I don't know what I could do at this point to generate a popup and populate it with the mail content.



P.S. Assuming I get this working well, this would be a nice plugin. It seems that right now, you have either email delivery, no email delivery, or no email but logging. It would be nice to have this as a fourth option.

(funny that I keep answering my own question)

Ok, I'm really close to having this working. The only thing is that I have a helper method that builds the popup window and fills it but I need to explicitly include that at the bottom of the layout(s) that I want to have show the popup. I.e. at the bottom of the main layout, I have:

<%= show_demo_emails %>

I wonder: Is there any way to have that automatically appended to the output? i.e. some hook somewhere that I can just call the helper method, which spits out some javascript code for the popup window, and slap it on the end of the response call?

My ideal is having all this happen in an application with the only actual change being made by the developer is setting the one line in the environment file:

config.action_mailer.delivery_method = :demo