<title browser-title='Mailing Forms : Resin Tutorial'>
Mailing Forms
</title>

<p/>A convenient way of gathering form data is simply to mail the form
results to a mailbox.  Mail is the most effective push technology.

<p>Sending mail with Resin is just like writing to a file.  Resin
recycles APIs to reduce information pollution.  Its VFS (virtual file
system) extends and simplifies java.io.  Sending mail is just like
writing to a file.  Resin's <ct:var/Path/> class is like <ct:var/File/> and
its <ct:var/WriteStream/> is a combination of <ct:var/OutputStream/> and
<ct:var/PrintWriter/>. 

<ct:example>
&lt;%@ page language=java %>
&lt;%@ page import='com.caucho.vfs.*' %>
&lt;%@ page import='java.util.*' %>

&lt;%
Path mail;
mail = Pwd.lookup("mailto:survey?subject='Colors'");
WriteStream os = mail.openWrite();

Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
  String key = (String) e.nextElement();
  String value = request.getParameter(key);

  os.println(key + ": " + value);
}

os.close();
%&gt;

&lt;h1&gt;Thank you for your response.&lt;/h1&gt;

</ct:example>
<ct:results>
name: Kermit the Frog
color: green
</ct:results>

<p>The example mails results to a user named <ct:var/survey/> on the web
server.  The subject of the mail is <ct:var/Colors/>.  Scripts can add
their own mail headers, including <ct:var/cc/>, <ct:var/bcc/>, and even
<ct:var/from/>.  To add multiple headers, separate them by
<ct:var/&amp;/>.

<ct:example>
Pwd.lookup("mailto:you?subject=test&bcc=me");
</ct:example>
