You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kaj Kandler <Ka...@Conficio.com> on 2006/05/18 03:30:25 UTC

Sending E-Mail with CForms

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,
has anybody an example "how to send e-mail" from Flow Script?

I do have set up a cocoon form with template and a flow script. I'd like
to peak at someones code for sending an e-mail.

I have found samples using <action> and logicsheets. But I can't find
how to combine that with my CForm.

All help appreciated

Kaj
- --
KajKandler@Conficio.com

- -----------------------------------------------------
|  We produce animated software manuals that click  |
- -----------------------------------------------------
 Conficio
 http://www.conficio.com/
 P.O.Box 761062,  Melrose,
 MA 02176

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)

iD8DBQFEa84xRDUvrJRNjTARAlINAKCb8SBfTcR44jhyfandQFd5gKQNbACdGRGy
3BK+4rjZQAQn0RF7ZVPntjY=
=KTay
-----END PGP SIGNATURE-----

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


Re: Sending E-Mail with CForms

Posted by werner <we...@gefi.at>.
Hi Kaj,

if you want to do it the cocoon way, take the SendmailTransformer. I 
think using the logicsheet should work too, but it's considered "old 
fashion".  Be careful if you use an old Cocoon version (<2.1.9), because 
the SendmailTranformer had some bugs. If you need  more sophisticated 
features than the SendmailTranformer offers, then you will have to 
implement your own Class and use the JavaMail API directly. (You can 
even do that in Flowscript.) Just google around for some JavaMail 
samples and call that from Flowscript. The contents of the mail can be 
created from a pipline, flowscript, .... anything you want. HTH. There 
is not much documentation for sending mail with cocoon.

Werner

Kaj Kandler wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hi there,
>has anybody an example "how to send e-mail" from Flow Script?
>
>I do have set up a cocoon form with template and a flow script. I'd like
>to peak at someones code for sending an e-mail.
>
>I have found samples using <action> and logicsheets. But I can't find
>how to combine that with my CForm.
>
>All help appreciated
>
>Kaj
>- --
>KajKandler@Conficio.com
>
>- -----------------------------------------------------
>|  We produce animated software manuals that click  |
>- -----------------------------------------------------
> Conficio
> http://www.conficio.com/
> P.O.Box 761062,  Melrose,
> MA 02176
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.5 (MingW32)
>
>iD8DBQFEa84xRDUvrJRNjTARAlINAKCb8SBfTcR44jhyfandQFd5gKQNbACdGRGy
>3BK+4rjZQAQn0RF7ZVPntjY=
>=KTay
>-----END PGP SIGNATURE-----
>
>---------------------------------------------------------------------
>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: Sending E-Mail with CForms

Posted by Peter Sparkes <pe...@didm.co.uk>.
Kaj

Another way to send emails is using the SendMailTransformer:

http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/mail/transformation/SendMailTransformer.html

the  above gives a example

Peter

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hi there,
>has anybody an example "how to send e-mail" from Flow Script?
>
>I do have set up a cocoon form with template and a flow script. I'd like
>to peak at someones code for sending an e-mail.
>
>I have found samples using <action> and logicsheets. But I can't find
>how to combine that with my CForm.
>
>All help appreciated
>
>Kaj
>- --
>KajKandler@Conficio.com
>
>- -----------------------------------------------------
>|  We produce animated software manuals that click  |
>- -----------------------------------------------------
> Conficio
> http://www.conficio.com/
> P.O.Box 761062,  Melrose,
> MA 02176
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.5 (MingW32)
>
>iD8DBQFEa84xRDUvrJRNjTARAlINAKCb8SBfTcR44jhyfandQFd5gKQNbACdGRGy
>3BK+4rjZQAQn0RF7ZVPntjY=
>=KTay
>-----END PGP SIGNATURE-----
>
>---------------------------------------------------------------------
>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


AW: Sending E-Mail with CForms

Posted by Christofer Dutz <du...@c-ware.de>.
Hi Kaj 

I have another solution for you (Seems as if we were both working on the same stuff) ;)

For sending Emails I use the SendmailTransformer. When starting work on this I had to realize that there is very little information available on the sendmail transformer ... here the Pipelines, Flowscript and XSLTs:

<map:transformers default="xslt">
	...
	<map:transformer logger="sitemap.transformer.sendmail" name="sendmail" src="org.apache.cocoon.mail.transformation.SendMailTransformer"/>
	...
</map:transformers>
...
<map:pipeline>
	<map:match pattern="send-email">
		<map:generate src="module:flow-attr:cart" /> 
		<map:transform src="stylesheets/cart2email.xsl">
			<map:parameter name="cartTotal" value="{flow-attr:cartTotal}"/>
			<map:parameter name="shippingCosts" value="{flow-attr:shippingCosts}"/>
		</map:transform>
		<map:transform type="sendmail" /> 
		<map:transform src="stylesheets/email2html.xsl" /> 
		<map:transform src="stylesheets/master.xsl">
			<map:parameter name="single-page" value="true"/>
		</map:transform>
		<map:serialize/>
	</map:match>
</map:pipeline>

The cart2email.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:param name="cartTotal" select="1234.56"/>
	<xsl:param name="shippingCosts" select="342.35"/>
	
	<xsl:template match="/">
		<document xmlns:email="http://apache.org/cocoon/transformation/sendmail">
			<email:sendmail>
				<email:smtphost>mail.yoursmpthost.de</email:smtphost>
				<email:from>shop@domain.de</email:from>
				<email:to>bestellung@domain.de</email:to>
				<email:to><xsl:value-of select="/cart/billingAddress/@email"/></email:to>
				<email:subject>Ihre Bestellung auf www.CoolCocoonShop.de</email:subject>
				<email:body><![CDATA[
					<p>Hiermit bestätigen wir den Erhalt Ihrer Bestellung.</p>
					
					<p>Es wurden folgende Produkte bestellt:
					<table>
						<tr>
							<th>Bezeichung:</th>
							<th>Menge:</th>
							<th>Einzelpreis:</th>
							<th>Gesamtpreis:</th>
						</tr>]]>
						<xsl:for-each select="/cart/cartContent/content/product">
							<![CDATA[<tr>
								<td>]]><xsl:value-of select="@product"/><![CDATA[</td>
								<td style="text-align:right;">]]><xsl:value-of select="format-number(@count, '#0')"/><![CDATA[</td>
								<td style="text-align:right;">]]><xsl:value-of select="format-number(@price, '#0.00')"/><![CDATA[€</td>
								<td style="text-align:right;">]]><xsl:value-of select="format-number(number(@count) * number(@price), '#0.00')"/><![CDATA[€</td>
							</tr>]]>
						</xsl:for-each>
						<![CDATA[<tr>
							<td>Gesamt Bestellwert:</td>
							<td colspan="3" style="text-align:right;">]]><xsl:value-of select="format-number($cartTotal, '####0.00')"/><![CDATA[€</td>
						</tr>
						<tr>
							<td>16% MWSt.:</td>
							<td colspan="3" style="text-align:right;">]]><xsl:value-of select="format-number((number($cartTotal) div 1.16) * 0.16, '#####0.00')"/><![CDATA[€</td>
						</tr>
						<tr>
							<td>Porto & Verpackung:</td>
							<td colspan="3" style="text-align:right;">]]><xsl:value-of select="format-number($shippingCosts, '#####0.00')"/><![CDATA[€</td>
						</tr>
						<tr>
							<td>Gesamtpreis (incl. 16% MWSt.):</td>
							<td colspan="3" style="text-align:right;">]]><xsl:value-of select="format-number($cartTotal + $shippingCosts, '#####0.00')"/><![CDATA[€</td>
						</tr>
					</table>
					</p>
					
					<p>Es wurde die folgende Rechnungsanschrift angegeben:<br/>]]>
						<xsl:value-of select="/cart/billingAddress/@title"/> <xsl:value-of select="/cart/billingAddress/@firstName"/> <xsl:value-of select="/cart/billingAddress/@lastName"/><![CDATA[<br/>]]>
						<xsl:value-of select="/cart/billingAddress/@company"/><![CDATA[<br/>]]>
						<xsl:value-of select="/cart/billingAddress/@street"/><![CDATA[<br/>]]>
						<xsl:value-of select="/cart/billingAddress/@zip"/> <xsl:value-of select="/cart/billingAddress/@city"/><![CDATA[<br/>]]>
						<xsl:value-of select="/cart/billingAddress/@country"/><![CDATA[<br/>]]>
						Telefon:	<xsl:value-of select="/cart/billingAddress/@phone"/><![CDATA[<br/>]]>
						Email:	<xsl:value-of select="/cart/billingAddress/@email"/><![CDATA[<br/>
					</p>

					<p>]]>
						<xsl:choose>
							<xsl:when test="/cart/billingAddress/@differentShippingAddress = 'true'">
								<![CDATA[Die Lieferung der Ware erfolgt an folgende, von der Rechnungsanschrift abweichenden Lieferanschrift:<br/>]]>
								<xsl:value-of select="/cart/shippingAddress/@title"/> <xsl:value-of select="/cart/shippingAddress/@firstName"/> <xsl:value-of select="/cart/shippingAddress/@lastName"/><![CDATA[<br/>]]>
								<xsl:value-of select="/cart/shippingAddress/@company"/><![CDATA[<br/>]]>
								<xsl:value-of select="/cart/shippingAddress/@street"/><![CDATA[<br/>]]>
								<xsl:value-of select="/cart/shippingAddress/@zip"/> <xsl:value-of select="/cart/shippingAddress/@city"/><![CDATA[<br/>]]>
								<xsl:value-of select="/cart/shippingAddress/@country"/><![CDATA[<br/>]]>
							</xsl:when>
							<xsl:otherwise>
								<![CDATA[Die Lieferung der Ware erfolgt an die oben genannte Adresse.<br/>]]>
							</xsl:otherwise>
						</xsl:choose>
						<xsl:if test="/cart/cartContent/alternateFormat = 'yes'">
							<![CDATA[<br/>Falls A7 zur Zeit nicht lieferbar ist, bin ich damit Einverstanden zum gleichen Preis das entsprechende Bild im größeren Format DIN A6 zu erhalten.<br/>]]>
						</xsl:if>
						<xsl:if test="string-length(/cart/notes) &gt; 0">
							<![CDATA[<br/>Es wurden folgende Hinweise angegeben:<br/>]]>
							<xsl:value-of select="/cart/notes"/>
						</xsl:if>
					<![CDATA[</p>			
			
					<p>Bei dieser Mail handelt es sich um die Bestätigung, dass Ihre Bestellung entgegen genommen wurde.</p>
					<p>Vielen Dank für Ihren Auftrag.</p>
					<p>Mit freundlichen Grüßen,<br/>
						Ihr Espirit-Team
					</p>]]>
				</email:body>
			</email:sendmail>
		</document>
	</xsl:template>
</xsl:stylesheet>

Now please don't crucify me for not translating the code ;)

And last but not least the Flowscript:

cocoon.sendPage("send-email", {cart: Packages.org.apache.axis.utils.XMLUtils.DocumentToString(cart).getBytes("UTF-8"), cartTotal:calculateCartTotal(), shippingCosts:calculateShippingCosts()});

I have to mention, that my cart is a plain old W3C Dom object. I sort of have to serialize it, if I want to add it ... don't really know why, but it works ;)

Hope I could help.

Chris

-----Ursprüngliche Nachricht-----
Von: Kaj Kandler [mailto:KajKandler@Conficio.com] 
Gesendet: Donnerstag, 18. Mai 2006 03:30
An: users@cocoon.apache.org
Betreff: Sending E-Mail with CForms

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,
has anybody an example "how to send e-mail" from Flow Script?

I do have set up a cocoon form with template and a flow script. I'd like
to peak at someones code for sending an e-mail.

I have found samples using <action> and logicsheets. But I can't find
how to combine that with my CForm.

All help appreciated

Kaj
- --
KajKandler@Conficio.com

- -----------------------------------------------------
|  We produce animated software manuals that click  |
- -----------------------------------------------------
 Conficio
 http://www.conficio.com/
 P.O.Box 761062,  Melrose,
 MA 02176

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)

iD8DBQFEa84xRDUvrJRNjTARAlINAKCb8SBfTcR44jhyfandQFd5gKQNbACdGRGy
3BK+4rjZQAQn0RF7ZVPntjY=
=KTay
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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