You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christofer Dutz <du...@c-ware.de> on 2005/10/09 12:46:17 UTC

generating emails from flow dom object

Hi.

 

I am working on this for quite some time and my brain is running dry at the
moment :-(

I have a small shoping cart, where all information is stored in a simple w3c
dom object. What I would like to know how I can do the following:

 

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

3.      send the email to a fixed address and one defined in the dom-object

4.      show the user some failure/success page

 

There seem to be several approaches, but I couldn't get them to work.

Any hints or howtos for this? I think this should be something that
shouldn't be too special.

 

Chris

 


AW: generating emails from flow dom object

Posted by Christofer Dutz <du...@c-ware.de>.
Thanks for that hint. I already thought of this but dropped the idea because
it seemed to be impossible to gen further information about it. This seems
to be the cleanest approach so I'll try that.

Chris

-----Ursprüngliche Nachricht-----
Von: Christoph Hermann [mailto:christoph.hermann@guschtel.de] 
Gesendet: Sonntag, 9. Oktober 2005 13:52
An: users@cocoon.apache.org
Betreff: Re: generating emails from flow dom object

Am Sonntag, 9. Oktober 2005 12:46 schrieb Christofer Dutz:

Hello,

> I am working on this for quite some time and my brain is running dry at
the
> moment :-(
>
> I have a small shoping cart, where all information is stored in a simple
> w3c dom object. What I would like to know how I can do the following:


> 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
> 3.      send the email to a fixed address and one defined in the
dom-object
> 4.      show the user some failure/success page

You could just do it like this:

(from flow):
cocoon.sendPage("my-email-pipeline",{data:mydomdata});

and then

<map:match pattern="my-email-pipeline">
<map:generate src="module:flow-attr:data" />
<map:transform src="data2email.xsl" />
<map:transform type="sendmail" />
<map:transform src="email2html.xsl" />
<map:serialize type="html" />
</map>

See the docs of the sendmailtransformer on how to send an email.

HTH
Christoph

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: generating emails from flow dom object

Posted by Christoph Hermann <ch...@guschtel.de>.
Am Sonntag, 9. Oktober 2005 12:46 schrieb Christofer Dutz:

Hello,

> I am working on this for quite some time and my brain is running dry at the
> moment :-(
>
> I have a small shoping cart, where all information is stored in a simple
> w3c dom object. What I would like to know how I can do the following:


> 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
> 3.      send the email to a fixed address and one defined in the dom-object
> 4.      show the user some failure/success page

You could just do it like this:

(from flow):
cocoon.sendPage("my-email-pipeline",{data:mydomdata});

and then

<map:match pattern="my-email-pipeline">
<map:generate src="module:flow-attr:data" />
<map:transform src="data2email.xsl" />
<map:transform type="sendmail" />
<map:transform src="email2html.xsl" />
<map:serialize type="html" />
</map>

See the docs of the sendmailtransformer on how to send an email.

HTH
Christoph

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: generating emails from flow dom object

Posted by Johannes Textor <te...@zeile2.de>.
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,"r1@test.dde");
	//msg.setRecipients(javax.mail.Message.RecipientType.CC,"r2@test.de");
	// 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: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org