Hi Christofer, one suggestion how to do this:
> Generate and send a nicely formatted Email from the dom-object: > > 1. somehow generate content form the flow object > > 2. do an XSLT to make it look nice Create a pipeline that generates (X)HTML from your flow object. use the module source (see also http://www.planetcocoon.com/recipes - Inject flowscript variables into a pipeline) <map:match pattern="cart.html"> <map:generate src="module:flow-attr:cart"/> <map:transform src="stylesheets/cartxml2html.xsl"/> <map:serialize type="xhtml" /> </map:match> It's good IMHO to do this in a seperate pipeline, since you might reuse this functionality somewhere else, and it makes it easier to test. So, during development, test your pipeline with "cocoon.sendPage( 'cart.html', { cart: cart } ) " where cart is the variable containing your flowscript dom object. > 3. send the email to a fixed address and one defined in the dom-object For this task, you can use the sendmail transformer, or use the java mail api directly from flowscript- I prefer the latter. To install the java mail api (you also have to do this when you want to use the sendmail transformer), download it from sun, along with the Java Activation Framwork. Copy activation.jar and the JARs from the mail api to WEB-INF/lib. Then you can use Java Mail from flowscript, or a custom java object. I have written a sendmail function for a similar task that looks like the following: function sendmail(from, subject, message){ //Set the host smtp address var mailprops = new java.util.Properties(); mailprops.put("mail.smtp.host", "localhost"); // create some properties and get the default Session var session = javax.mail.Session.getDefaultInstance(mailprops, null); session.setDebug(false); // create a message var msg = new javax.mail.internet.MimeMessage(session); msg.setRecipients(javax.mail.Message.RecipientType.TO,"[EMAIL PROTECTED]"); //msg.setRecipients(javax.mail.Message.RecipientType.CC,"[EMAIL PROTECTED]"); // Optional : You can also set your custom headers in the Email if you Want //msg.addHeader("MyHeaderName", "myHeaderValue"); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/html"); msg.setSentDate(new java.util.Date()); try { var addressFrom = new javax.mail.internet.InternetAddress(from); msg.setFrom(addressFrom); javax.mail.Transport.send(msg); } catch(e) { // Versand hat nicht funktioniert. cocoon.sendPage("failure.html"); return; } } > 4. show the user some failure/success page In the function above, I use two pipelines (success.html/failure.html) for doing this. Then, the sendmail function is invoked as follows: // alles fertig, mail verschicken. var stream = new java.io.ByteArrayOutputStream(); cocoon.processPipelineTo( "cart.html", { cart:cart }, stream ); sendmail( customer.getEmail(), "Online-Shop Bestellung", stream.toString() ); // Bestätigung schicken cocoon.sendPage("success.html"); return; > > > There seem to be several approaches, but I couldn’t get them to work. In Cocoon, there's always a myriad of ways to do something, that's why it can be so confusing sometimes. HTH, Johannes --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
