How to use the email address chooser task for Windows Phone 8

August 19, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

Use the email address chooser task to obtain the email address of a contact selected by the user. This task launches the Contacts application so that the user can choose a contact. If the user completes the task, an event is raised and the event handler receives an address in the result.

By using Choosers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

NoteNote:

The Windows Phone SDK includes APIs that you can use to retrieve contact information from within your application. For more information, see Contacts and Calendar for Windows Phone 8.

To use the email address chooser task

  1. Add the following statement to your code.

    using Microsoft.Phone.Tasks;
    
  2. Declare the task object. It must have page scope, so declare it in your page before the constructor.

    EmailAddressChooserTask emailAddressChooserTask;
    
  3. Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.

    emailAddressChooserTask = new EmailAddressChooserTask();
    emailAddressChooserTask.Completed += new EventHandler<EmailResult>(emailAddressChooserTask_Completed);
    
  4. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

    
    
    
    emailAddressChooserTask.Show();
    
    
    
    
    
    
    
  5. Add the code for the completed event handler to your page. This code runs after the user completes the task. The result is an EmailResult object that contains the name and email address of the contact. There is sample code to compose a new email message using the retrieved address. For more information, see How to use the email compose task for Windows Phone 8.

    void emailAddressChooserTask_Completed(object sender, EmailResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            MessageBox.Show("The email for " + e.DisplayName + " is " + e.Email);
    
            //Code to send a new email message using the retrieved email address.
            //EmailComposeTask emailComposeTask = new EmailComposeTask();
            //emailComposeTask.To = e.Email;
            //emailComposeTask.Subject = e.DisplayName + ", here is an email from my app!";
            //emailComposeTask.Show();
        }
    }
    

Show:
© 2014 Microsoft