# Demo Popup Emails?

**URL:** <https://www.ruby-forum.com/t/demo-popup-emails/132993>\
**Category:** Rails\
**Created:** [March 26, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993 "2008-03-26T15:52:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [March 26, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993/1 "2008-03-26T15:52:31Z")

</div>

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!

-Dan

---

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [March 26, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993/2 "2008-03-26T15:58:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [March 26, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993/3 "2008-03-26T16:10:21Z")

</div>

Thorsten,

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?

On Mar 26, 8:58 am, Thorsten M. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [March 26, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993/4 "2008-03-26T19:53:21Z")

</div>

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.

Thoughts?

-Dan

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.

---

<div class="post-metadata">

**Author:** ![Danimal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bb73d2/32.png) [@Danimal](https://www.ruby-forum.com/u/Danimal)\
**Post date:** [March 26, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/demo-popup-emails/132993/5 "2008-03-26T21:00:25Z")

</div>

(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

Thanks!
