Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win8/WinRT - How to add line breaks in email body

In my Windows 8 Store app, I have a Send Email button on a page and users are able to click it and send us an email for some general enquiries.

I need to pre-load some text in the email body but I can't seem to add line breaks to it. I tried Environment.NewLine and "\r\n". None of them works.

var mailto = new Uri("mailto:[email protected]&subject=Hello world&body=Hi," + Environment.NewLine + "Can you please ..."); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

When I run it, I get "Hi,Can you please...". The line break is omitted.

like image 413
Justin XL Avatar asked Oct 20 '12 00:10

Justin XL


2 Answers

Try using "%0d%0a" as your line break, as in

"Hi,%0d%0aCan you please..."

That's a URL-encoded ASCII CR/LF sequence. That works for me for the built-in Mail app but you don't have any particular guarantee that it would work for any arbitrary mail app that the user might install in the future.

like image 58
Travis Avatar answered Nov 12 '22 22:11

Travis


The reason it doesn't work is because you're launching a Uri, Uris require that their contents be UrlEncoded / UrlEncodable. In the case of Environment.Newline etc you'd get an invalid Uri.

You can counter this by UrlEncoding the Environment Newline like this:

System.Net.WebUtility.UrlEncode(Environment.NewLine)
like image 5
Tristan Warner-Smith Avatar answered Nov 13 '22 00:11

Tristan Warner-Smith