Hi,
First of all what is my goal: I have simple input box (aka search site box) where user can put its email address. The point is to send an email containing its email address to some system account.

I am using simple usecase which calls .js script. You can see all related files bellow.

My problem is, how to get the user email (value from the input box) in my .js script??? I've tried something like cocoon.getRequest but no luck.

Many thanks,
Milan

ps: to whom want to use this: you have to copy mail jar file to your lib dir. have a look here - http://solprovider.com/lenya/flowemail


On main page:
=============
<form>
  <strong>Subscribe:</strong>:
  <input type="text" name="email" class="formfield"/>
  <input type="hidden" name="lenya.usecase" value="subscribe"/>
  <input type="hidden" name="language" value="en"/>
</form>

usecase-subscribe.xmap:
=======================
<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0";>
  <map:flow language="javascript">
    <map:script src="flow/subscribe.js"/>
  </map:flow>
  <map:pipelines>
    <map:pipeline>
      <map:match pattern="**.html">
        <map:call function="subscribe_mail"/>
      </map:match>
      <map:match pattern="subscribe-success">
        <map:redirect-to uri="/"/>
      </map:match>
    </map:pipeline>
  </map:pipelines>
</map:sitemap>

and finaly the script flow/subscribe.js:
========================================
function subscribe_mail() {
  var properties = new Packages.java.util.Properties();
  properties.setProperty("protocol", "smtp");
  properties.setProperty("type", "transport");
  properties.setProperty("class", "com.sun.mail.smtp.SMTPTransport");
  properties.setProperty("mail.smtp.host", "localhost")

  var session = new Packages.javax.mail.Session.getInstance(properties);
  var message = new Packages.com.sun.mail.smtp.SMTPMessage(session);
  var address = new Packages.javax.mail.internet.InternetAddress();


  message.setSubject("Test JavaMail");
  message.setText("Mail: " + usermail, "UTF-8");
  address.setAddress("XXXX");
  message.setFrom(address);
  address.setAddress("XXXXX");
message.addRecipient(Packages.javax.mail.Message.RecipientType.TO, address);

  var urlname = new Packages.javax.mail.URLName("smtp://localhost")
var transport = new Packages.com.sun.mail.smtp.SMTPTransport(session, urlname);
  transport.send(message);
  cocoon.sendPage("subscribe-success");
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to