11 Comments

image

In a Windows Phone 7 app, sending an email requires an instance of EmailComposeTask. EmailComposeTask is really easy to use and self-explanatory:

EmailComposeTask emailComposeTask = new EmailComposeTask();

emailComposeTask.Subject = "message subject"; 
emailComposeTask.Body = "message body"; 
emailComposeTask.To = "recipient@example.com"; 
emailComposeTask.Show();

In Windows 8 Metro app, there’s no EmailComposeTask. Instead, you create a “mailto” –uri and launch it:

var mailto = new Uri("mailto:recipient@example.com"); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

But when compared to an EmailComposeTask, this only fills the “To” –part, but what about the “Subject” and “Body”? Well, the mailto-syntax allows you to define these as query parameters. For example, here’s an example of defining the “subject”, “body” and “to” –fields from code. The uri is automatically escaped by the platform:

var mailto = new Uri("mailto:?to=recipient@example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app."); 
await Windows.System.Launcher.LaunchUriAsync(mailto);

image

With this knowledge, it would be rather easy to build a custom EmailComposeTask for Windows 8.

Comments

Comment by Cloud

Thanks a lot!

Cloud
Comment by lui

Hey, a question. the tab and end of line chars are being removed from the email body. how do I make the MailFormat = to text?

lui
Comment by Mikael Koskinen

Good question. I'm not actually sure how this should be handled. It's been some time from your question so I wonder if you were already able to solve this?

Comment by Kiril Stanoev

My email app is Outlook and when executing the suggested code, the To field is not prefilled with the desired address...

Comment by Brandon

Would like to see an example of a very custom e-mail, say one that includes debug info about the system as developers may like to implement in part of crash reporting. I am having trouble getting newlines to show up in the e-mail body either with rn or <br/>
Thanks in advance!

Brandon
Comment by YIN

Hello , My question can be silly. I 'm using default
mail client . I want to close the mail app after send mail.

YIN
Comment by Tuğrul Emre Atalay

Thanks for this unique topic!

Tuğrul Emre Atalay
Comment by website design templates

website design templates...

Windows 8 Metro app: Sending an email. (Compared to Windows Phone 7’s EmailComposeTask) - Mikael Koskinen...

Comment by chordfinder

How to send HTML email? I tried

body=Hello world

but I don't see the bold text

chordfinder
Comment by Guillaume

same here...

Guillaume