Windows 8 Metro app: Sending an email. (Compared to Windows Phone 7’s EmailComposeTask)
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 = "firstname.lastname@example.org"; 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:email@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:?firstname.lastname@example.org&subject=The subject of an email&body=Hello from a Windows 8 Metro app."); await Windows.System.Launcher.LaunchUriAsync(mailto);
With this knowledge, it would be rather easy to build a custom EmailComposeTask for Windows 8.