Pitfalls with mailto-Links in Flash

October 20th, 2009 by max » (3) » AS3

In my last project I had some issues with IE8 (at customer-side), Mail (on agency-side) and my way of placing mailto-links.

In this project, the email-address and the subject come from a XML. This was my first setup:

XML-Node

<node contactAddress="support@acme.com" contactSubject="Kontakt über Homepage">

(Please notice: the german »Umlaut« in the subject)

AS3 (excerpt)

private function mailto(e:MouseEvent):void {
var mailaddress:String=XML.node.attribute("contactAddress");
var mailsubject:String=XML.node.attribute("contactSubject");
navigateToURL( new URLRequest( "mailto:"+mailaddress+"?subject="+mailsubject));
}

So, let’s see, what happened with different clients on different OS:

IE7, IE6, FF, Safari on WinXP worked without any problems (with Outlook Express). IE8 on WinXP opens a new Window with an error message (»Navigation wurde abgebrochen« / »Navigation to the webpage was canceled«), but opens Outlook (Express and Outlook 2007) with correct recipient and correct subject.
Every browser on Mac opens up Mail, but didn’t open a new eMail with recipient or subject.

To cut a long debugging-story short: please no german umlauts in mailsubject, so changing the XML-node the following mail, solved the problem:

<node contactAddress="support@acme.com" contactSubject="Kontakt per Homepage">

Nice, but still IE8 opens up a ugly window with the cancelation message. The solution here was the target-attribute of the navigateToUrl-Method: default is “_blank”, which I thought was the correct way to handle it, because I didn’t want the page to unload, if the mailto-Link was clicked. Turned out, that when you use the code in following way, the page doesn’t unload and new tabs/windows are surpressed.

private function mailto(e:MouseEvent):void {
var mailaddress:String=XML.node.attribute("contactAddress");
var mailsubject:String=XML.node.attribute("contactSubject");
navigateToURL( new URLRequest( "mailto:"+mailaddress+"?subject="+mailsubject), "_self");
}

Conclusion: don’t use Umlauts (and probably no other special characters) with OS X, don’t use “_blank” or default.

Max Schalch

About the author

Max, twentysomething, is a designer and developer from Bavaria. He runs his own business and was long time employed in media and advertising.
On fASforward.com he blogs about ActionScript, Flash, ColdFusion and all the other stuff.

Twitter | XING | LinkedIn | Facebook

3 Responses to “Pitfalls with mailto-Links in Flash”

  1. fasforward-reader Jason writes:

    Use encodeURIComponent on your URL parts, e.g.:

    var fileName:String = itemPath.substring( itemPath.lastIndexOf( “/” ) 1 );
    var subject:String = encodeURIComponent( “Download ” fileName );
    var date:Date = dateField.selectedDate;
    date.setHours( 23, 59, 59, 0 );
    var link:String = “mailto:” recipientEmail.text “?subject=”
    subject “

  2. fasforward-reader 3vilguy writes:

    I got similar problem with URLRequest but not for mail and encodeURI() helped me so much. Thx Jason.

  3. fasforward-reader am writes:

    haha, nice problem solving, just avoid the Umlaut ;)

Leave a Reply