Flex Quick Tip: Launching email client on event
The flash.net package provides a nice solution for launching the default mail client on a mailto: link in Flex, The sendToURL() function will launch the mail client without opening a new browser window.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="components.*"
layout="absolute" borderColor="#000000">
<mx:Script>
<![CDATA[
import flash.net.*;
public function launchMailer(e:Event):void{
var mailLink:URLRequest = new URLRequest("mailto:" + e.currentTarget.text);
navigateToURL( mailLink, "_self" );
}
]]>
</mx:Script>
<mx:Canvas>
<mx:Panel>
<mx:Text text="John Doe" />
<mx:Text text="jdoe@somecompany.com" click="launchMailer(event)" />
</mx:Panel>
</mx:Canvas>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="components.*"
layout="absolute" borderColor="#000000">
<mx:Script>
<![CDATA[
import flash.net.*;
public function launchMailer(e:Event):void{
var mailLink:URLRequest = new URLRequest("mailto:" + e.currentTarget.text);
navigateToURL( mailLink, "_self" );
}
]]>
</mx:Script>
<mx:Canvas>
<mx:Panel>
<mx:Text text="John Doe" />
<mx:Text text="jdoe@somecompany.com" click="launchMailer(event)" />
</mx:Panel>
</mx:Canvas>
</mx:Application>
Colorized by: CarlosAg.CodeColorizer


I've got it working perfectly in IE, but I can't get it to work with FireFox. Weird. It may be problems with my FF. When I first tried it, FF kept trying to open up to Gmail instead of Outlook, even though Outlook is my default. I fixed that, FF now opens Outlook for other mailto links, but when I click on the links in my Flex app I get nothing.
Have you run across this before, or is it just a problem with my implementation of FireFox?
blinders off.
Change the function to:
navigateToURL( mailLink, "_self" );
I just tested that function and it works in both browsers without launching
a secondary blank window.
I also used the navigateToURL() method as the sendToURL() didn't work.
Otherwise this worked fine. I have an AIR b3 app, running on Mac OS X 10.5.2 and sending email through Apple Mail.
That was a hold over from playing around with
some URL's and I hadn't noticed it since
Lotus Notes trimmed it.
private function mailTest():void {
var urlRequest:URLRequest =
new URLRequest("mailto:someone@company.com?subject=Widget testing&body=this is the body content");
navigateToURL(urlRequest, "_self");
trace ("mailtest");
}
Good precise read!
Example updated.