# Using mailto in ionic?

**URL:** <https://forum.ionicframework.com/t/using-mailto-in-ionic/5361>\
**Category:** uncategorized\
**Created:** [June 8, 2014, 8:06am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361 "2014-06-08T08:06:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![10chars](https://avatars.discourse-cdn.com/v4/letter/1/c57346/32.png) [@10chars](https://forum.ionicframework.com/u/10chars)\
**Post date:** [June 8, 2014, 8:06am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/1 "2014-06-08T08:06:15Z")

</div>

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> 

```

Controller:

```
$scope.emailContactDetails = function(){
    var link = "mailto:?subject=Contact Detail&body="+
                   "Name: " + $scope.contact.name + "Number: " + $scope.contact.phone;     
    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?

Thanks!

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [June 8, 2014, 8:16am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/2 "2014-06-08T08:16:14Z")

</div>

Hey,

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

---

<div class="post-metadata">

**Author:** ![10chars](https://avatars.discourse-cdn.com/v4/letter/1/c57346/32.png) [@10chars](https://forum.ionicframework.com/u/10chars)\
**Post date:** [June 9, 2014, 1:53am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/3 "2014-06-09T01:53:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![biapar](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/biapar/32/64378_2.png) [@biapar](https://forum.ionicframework.com/u/biapar)\
**Post date:** [June 9, 2014, 3:00pm UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/4 "2014-06-09T15:00:29Z")

</div>

Could you post your code to help others? thx

---

<div class="post-metadata">

**Author:** ![biapar](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/biapar/32/64378_2.png) [@biapar](https://forum.ionicframework.com/u/biapar)\
**Post date:** [June 9, 2014, 3:02pm UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/5 "2014-06-09T15:02:20Z")

</div>

> [@10chars](#):
>
> window.location.href = link;

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

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [June 9, 2014, 3:58pm UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/6 "2014-06-09T15:58:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zhouhaowowtv](https://avatars.discourse-cdn.com/v4/letter/z/8e8cbc/32.png) [@zhouhaowowtv](https://forum.ionicframework.com/u/zhouhaowowtv)\
**Post date:** [February 27, 2016, 6:47am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/7 "2016-02-27T06:47:31Z")

</div>

> [@biapar](#):
>
> $window.location.href

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

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [February 27, 2016, 10:04am UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/8 "2016-02-27T10:04:45Z")

</div>

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

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

> **[apache/cordova-plugin-whitelist](https://github.com/apache/cordova-plugin-whitelist#intent-whitelist)**
>
> cordova-plugin-whitelist - Mirror of Apache Cordova plugin whitelist

---

<div class="post-metadata">

**Author:** ![zhouhaowowtv](https://avatars.discourse-cdn.com/v4/letter/z/8e8cbc/32.png) [@zhouhaowowtv](https://forum.ionicframework.com/u/zhouhaowowtv)\
**Post date:** [March 1, 2016, 1:35pm UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/9 "2016-03-01T13:35:15Z")

</div>

Only work in device.

---

<div class="post-metadata">

**Author:** ![websbess](https://avatars.discourse-cdn.com/v4/letter/w/b19c9b/32.png) [@websbess](https://forum.ionicframework.com/u/websbess)\
**Post date:** [August 22, 2016, 10:21pm UTC](https://forum.ionicframework.com/t/using-mailto-in-ionic/5361/10 "2016-08-22T22:21:20Z")

</div>

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.
