- Home /
How do I send an email on IOS using Application.OpenURL with more than one line of body text?
This works...
Application.OpenURL ("mailto:someone@gmail.com?subject=EmailSubject&body=EmailBody");
This doesn't...
Application.OpenURL ("mailto:someone@gmail.com?subject=EmailSubject&body=Email\n\rBody");
Any help greatly appreciated :)
Answer by Kryptos · Dec 04, 2012 at 09:09 AM
Did you try double-escaping the backslashes? Something like:
Application.OpenURL ("mailto:someone@gmail.com?subject=EmailSubject&body=Email\\r\\nBody");
Or maybe you need to use HTML URL encoded entities.
Application.OpenURL ("mailto:someone@gmail.com?subject=EmailSubject&body=Email%0D%0ABody");
Take also a look at C# verbatim string literals:
@"first line blabla
second line thingy."
the second answer (use HT$$anonymous$$L UTL encoded entities) works perfectly fine! thanks.
Answer by Shanlu · Aug 18, 2014 at 12:13 PM
You have to encode the url inorder to open it .Use the below link for encoding and decoding http://meyerweb.com/eric/tools/dencoder/
Answer by huminado · Apr 04, 2014 at 01:38 AM
%0A%0D
For your example:
Application.OpenURL ("mailto:someone@gmail.com?subject=EmailSubject&body=Email%0A%0DBody");
Answer by IMD · Jun 27, 2019 at 05:06 PM
Made up a little dynamic function off the Unity API which will 'smart escape' your url without messing with the root domain; enjoy.
public static string SmartEscapeURL(string url) {
string escapedArgs = "";
string[] parts = url.Split('?');
if (parts.Length == 1) return url;
string[] args = parts[1].Split('&');
for (int i = 0; i < args.Length; i++) {
string[] kvp = args[i].Split('=');
if (kvp.Length == 2) {
escapedArgs += String.Format("{0}={1}",
WWW.EscapeURL(kvp[0]).Replace("+", "%20") ,
WWW.EscapeURL(kvp[1]).Replace("+", "%20"));
if (i < args.Length - 1) escapedArgs += "&";
}
}
string eUrl = parts[0] + "?" + escapedArgs;
return eUrl;
}
Isaac