Preparing an Email with the EmailComposeTask

,

The EmailComposeTask launches the Windows Phone Email application, which displays a page allowing the user to create a new email.


Note

The email is not sent until it is initiated by the user.


You can optionally specify recipients, a message subject, and a message body, which are prepopulated in the new email, as shown in the following excerpt:

EmailComposeTask task = new EmailComposeTask
                              {
                                  To = "[email protected]",
                                  Cc = "[email protected]",
                                  Subject = "Windows Phone",
                                  Body = "Hi from Windows Phone!"
                              };
task.Show();

Multiple recipients in the To and Cc properties can be specified by delimiting the address with a semicolon character.

Sample Overview

Example code for the EmailComposeTask can be found in the EmailViewModel in the downloadable sample code. The EmailView allows the user to select the recipient and to launch a new EmailComposeTask via a button (shown previously in Figure 14.5).

The view’s Compose Email button is bound to a viewmodel command called ComposeCommand.

When executed, the ComposeCommand creates a new EmailComposeTask and sets its To property to the text supplied by the EmailAddressChooserTask. This behavior is defined in the EmailViewModel constructor, as shown:

public EmailViewModel() : base("Email")
{
...
    composeCommand = new DelegateCommand(
        delegate
            {
                EmailComposeTask emailComposeTask
                    = new EmailComposeTask
                        {
                            To = toAddress,
                            Subject = "Windows Phone Unleashed",
                            Body = "Hi from Windows Phone!"
                        };
                emailComposeTask.Show();
            });
}

When the EmailComposeTask.Show method is called, the built-in Email application is launched. If the user has multiple email accounts defined on the device, the Email application prompts the user to select which account to use. The user is then presented with a new email message, prepopulated with the To, Cc, Subject, and Body properties of the EmailComposeTask.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.149.45