while(thoughts){ "i am writing"}

Just about anything… and everything :)

Archive for the ‘Coldfusion’ Category

Using Coldfusion Mail Services in Flex Applications

leave a comment »

Today we will discuss about mail services for Flex that were introduced with Coldfusion 9. One need to add cfservices.swc to the libs references to use the Mail tag in Flex.

Before you do this flex coding, you need to create/set appropriate permissions in your coldfusion server for the user that we will use in flex app to access the CF services.

Here is the code:

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:cf="coldfusion.service.mxml.*"
minWidth="955" minHeight="600">
<s:layout>
<s:VerticalLayout/>
</s:layout>

<fx:Script>
<![CDATA[
import coldfusion.service.events.ColdFusionServiceFaultEvent;
import coldfusion.service.events.ColdFusionServiceResultEvent;

import mx.controls.Alert;
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
cfMail.execute();
}

protected function cfMail_resultHandler(event:ColdFusionServiceResultEvent):void
{
// TODO Auto-generated method stub
Alert.show("In Result : "+event.message.toString());
}

protected function cfMail_faultHandler(event:ColdFusionServiceFaultEvent):void
{
// TODO Auto-generated method stub
Alert.show("In Fault : "+event.message.toString());
}

]]>
</fx:Script>

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<cf:Config id="conf"
cfServer="{serverIPTextInput.text}"
cfPort="{int(portTextInput.text)}"
cfContextRoot="{contextTextInput.text}"
servicePassword="{passwordTextInput.text}"
serviceUserName="{userIdTextInput.text}"/>

<cf:Mail id="cfMail"
to="{to.text}"
from="{from.text}"
subject="{subject.text}"
content="{body.text}"
userName="{userName.text}@gmail.com"
password="{password.text}"
port="465"
useSSL="true"
type="html"
server="smtp.gmail.com"
result="cfMail_resultHandler(event)"
fault="cfMail_faultHandler(event)"/>
</fx:Declarations>
<mx:Form direction="ltr">
<mx:FormItem label="Server IP">
<s:TextInput id="serverIPTextInput" text="127.0.0.1"/>
</mx:FormItem>
<mx:FormItem label="Port">
<s:TextInput id="portTextInput" text="8500"/>
</mx:FormItem>
<mx:FormItem label="Context(if any)">
<s:TextInput id="contextTextInput"/>
</mx:FormItem>
<mx:FormItem label="User Id">
<s:TextInput id="userIdTextInput" text="mdhanda"/>
</mx:FormItem>
<mx:FormItem label="Password">
<s:TextInput id="passwordTextInput" text="admin"/>
</mx:FormItem>
</mx:Form>

<mx:Form>
<mx:FormItem label="To">
<s:TextInput id="to" text="to_any_mail@gmail.com"/>
</mx:FormItem>
<mx:FormItem label="From">
<s:TextInput id="from" text="from_gmail_address@gmail.com"/>
</mx:FormItem>
<mx:FormItem label="Subject">
<s:TextInput id="subject" text="Test Mail.."/>
</mx:FormItem>
<mx:FormItem label="Message">
<s:TextInput id="body" text="Hiii"/>
</mx:FormItem>
<mx:FormItem label="Username">
<s:TextInput id="userName" text="from_gmail_username"/>
</mx:FormItem>
<mx:FormItem label="Password">
<s:TextInput id="password" displayAsPassword="true" text="password"/>
</mx:FormItem>
</mx:Form>
<s:Button label="Send Mail" click="button1_clickHandler(event)"/>
</s:Application>

 

One need to change the credentials in the above code to make it work.

Written by MD

October 23, 2010 at 4:31 PM

Follow

Get every new post delivered to your Inbox.