Solprovider Lenya Kongregate Registration for Free Flash Games and Chat with solprovider

Email

Setup

1. Download two files from Sun:
jaf-1_0_2-upd2.zip = Java Activation Framework
javamail-1_3_3-ea.zip = Java Mail

2. Unzip them

3. Put these two jars in build/lenya/webapp/WEB-INF/lib
jaf-1.0.2/activation.jar
javamail-1.3.3ea/mail.jar

4. Restart Lenya so the new Java libraries are noticed.

TestMail Usecase

1. Flow Javascript
FILE: {pub}/flow/testmail/code.js
function 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", "mail.example.com")
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("This is a test of JavaMail.", "UTF-8");
address.setAddress("from@example.com");
message.setFrom(address);
address.setAddress("to@example.com");
message.addRecipient(Packages.javax.mail.Message.RecipientType.TO, address);
var urlname = new Packages.javax.mail.URLName("smtp://mail.example.com")
var transport = new Packages.com.sun.mail.smtp.SMTPTransport(session, urlname);
transport.send(message);
cocoon.sendPage("testmail-success");
}


Notice setText() has a second parameter "UTF-8". That is pointless in this example, but very important if you are creating the text string from input from a Flow form. Without it, all double-byte input would be converted to question marks ('?':hex 73) and lost forever. With the setting, you can use something like:
"NAME: " + model.name + "\n" + model.comment

2. Change the mail server (twice) and the To and From addresses. HINT: Search for "example.com".

3. Usecase XMAP
FILE: {pub}/usecase-testmail.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/testmail/code.js"/>
</map:flow>
<map:pipelines>
<map:pipeline>
<map:match pattern="**.html">
<map:call function="mail"/>
</map:match>
<map:match pattern="testmail-success">
<map:redirect-to uri="/"/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>


4. Test. Just add "?lenya.usecase=testmail" to any URL and an email will be sent:
http://127.0.0.1:8888/default/live/index.html?lenya.usecase=testmail

The browser should return to the homepage. Check the Inbox of the To address to see the email.

<< XMAPs and XMLContact Us >>

Contact Solprovider
Paul Ercolino