Over a million developers have joined DZone.

Windows 8 Metro app: Sending an Email. (Compared to Windows Phone 7’s EmailComposeTask)

· Mobile Zone

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.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}