Using mailto in ionic?

Has anyone incorporated mailto links into their app. I’m currently trying to do it with something like…

<i class="ion-ios7-upload-outline" ng-click="emailContactDetails()"></i> 


$scope.emailContactDetails = function(){
    var link = "mailto:?subject=Contact Detail&body="+
                   "Name: " + $ + "Number: " + $;     
    window.location.href = link;

But I get the following error in the xcode console:

Failed to load webpage with error: The URL can’t be shown

Does anyone have any ideas?



first you should use $window in angular context if it is possible.

Second you have do decode your uri params because you produce invalid urls.
Use decodeUri or decodeUriComponent to decode special chars correctly (whitespaces and so on)!

E.g. ‘Contact Detail’ should be ‘Contact%20Detail’

Greetz Bengtler

Sweet! Thanks heaps for that.

That got rid of the error, and looks like it should be all working fine now, hopefully. The iPhone simulator doesn’t appear to have mail app functionality so I guess I’ll just have to wait 'til I can test it on a device properly.

Thanks again.

Could you post your code to help others? thx

Is $window.location.href = link; ? Must be passing $window as parameter controller?

Correct, you have to load $window in your controller function to use it.

But the “mailto” links to nothing. It will not open the mail application in my emulator and device.

since cordova introduced the whitelist plugin you have to allow special tags in your config.xml

<allow-intent href="mailto:*" />


Only work in device.

I know that this is an old thread but I just wanted to point out that this probably works on your device because you have a mail account added. mailto: will only work if a mail account is added, otherwise nothing will happen.