Bug 25584 - Starting a mail client from Device.OpenUri with a subject or body containing a space throws exception
Summary: Starting a mail client from Device.OpenUri with a subject or body containing ...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Mac OS
: Normal major
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-12-23 04:37 UTC by Johan Karlsson
Modified: 2015-07-06 11:28 UTC (History)
7 users (show)

Tags: AC
Is this bug a regression?: ---
Last known good build:

Reproduction of the error (19.29 KB, application/zip)
2014-12-23 04:37 UTC, Johan Karlsson

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Johan Karlsson 2014-12-23 04:37:11 UTC
Created attachment 9171 [details]
Reproduction of the error

Works on Android
Does NOT work on iOS (8.1) on an iPhone 5s.

Blog post about the reproduction of the issue: 

Attached a project reproducing the issue.

Adding spaces, not working
var uri = "mailto:info@johankarlsson.net?subject=more in subject&body=body";
    Device.OpenUri(new Uri(uri)); 

This gives you an "System.Exception: Could not initialize an instance of the type 'MonoTouch.Foundation.NSUrl': the native 'initWithString:' method returned nil."

Alright, so we URI encode it to

var uri = "mailto:info@johankarlsson.net?subject=more%20in%20subject&body=body";
    Device.OpenUri(new Uri(uri)); 

Same issue... And that's a bit weird since Apples own documentation states that this is the way to do it. (https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MailLinks/MailLinks.html#//apple_ref/doc/uid/TP40007899-CH4-SW1)

Trying Apples own example Uri
With a copy of the example Uri from Apples documentation it should work.

var uri = "mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20";
Device.OpenUri(new Uri(uri));  

It does not.
Comment 1 Parmendra Kumar 2014-12-23 06:00:26 UTC
I have checked this issue with attached sample and I am getting an exception with iOS, Its working fine on Android.

Screencast: http://www.screencast.com/t/yoRhoYxXr

ApplicationOutput: https://gist.github.com/Parmendrak/ea2bb0488da163156662
IDELog: https://gist.github.com/Parmendrak/b9cb65d6ae99792a5ce5
BuildLog: https://gist.github.com/Parmendrak/2a45c3c2b08da5a2a3b4

Environment info:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 7244769
Build date: 2014-12-11 14:54:30-0500

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 2 Stephane Delcroix 2015-06-15 07:11:35 UTC
This issue is fixed, for both versions (with or without encoding).

The fix will be part of 1.4.3 final
Comment 3 Parmendra Kumar 2015-07-06 11:28:38 UTC
I have checked this issue with X.F and its working fine at my end.

Hence closing this issue.