.--- On Mon, 13 Mar 2006, Ryan Perry wrote:
| I have a Mason page that I would like to have emailed to myself. How can I
| redirect output from within Mason so that a user can submit a form, Mason
| renders the page I want and emails the page, then Mason continues to render
| the user's page and output it as usual?
`---
As a mimimalistic example with no error checking:
- - - - - 8< - - - - - - - - - 8< - - - - - - -
<%once>
use Mail::Send;
</%once>
THIS IS A TEST.
<%filter>
my $msg = new Mail::Send;
$msg->to('[EMAIL PROTECTED]');
$msg->subject('The Web Page');
$msg->set("From", '[EMAIL PROTECTED]');
my $mail = $msg->open;
print $mail $_;
$mail->close;
</%filter>
- - - - - 8< - - - - - - - - - 8< - - - - - - -
You should receive: "THIS IS A TEST." in the body of this email, with
more or less whitespace around it. Note that this will provide the
content of this document only, and it will not include the rest of the
wrapping of autohandlers, etc., that it inherits from.
To mail the entire wrapped document, you'll need to go a step
further. First, add a default attribute to the document at the top
level of inheritance -- either the top level autohandler, or a master
handler that that may inherit from.
<%attr>
email_this_to_me => undef
<%attr>
Then, in the same top level wrapper, add a conditional and the same
mailer code to the filter section:
<%filter>
if ($m->request_comp->attr('email_this_to_me')) {
my $msg = new Mail::Send;
$msg->to('[EMAIL PROTECTED]');
$msg->subject('The Web Page');
$msg->set("From", '[EMAIL PROTECTED]');
my $mail = $msg->open;
print $mail $_;
$mail->close;
}
</%filter>
Then, in other documents, set the attribute to any true value, and
you'll have the entire rendered document mailed to you.
<%attr>
email_this_to_me => 1
</%attr>
Best regards,
-- Patrick
--
.------ Patrick M. Jordan ------. Random unused band name:
| Systems/Network Administrator | Zombie Grocery Invasion
`----- Antistatic Matrix -------'
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users