Click here to Skip to main content
12,997,210 members (80,924 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 19 Apr 2012

How to Send Email in WP7 using the EmailComposeTask?

, 19 Apr 2012
Rate this:
Please Sign up or sign in to vote.
How to send email in WP7 using the EmailComposeTask?

In the last blog post, we learnt "How to Save Email Address in WP7 using the SaveEmailAddressTask?" where we shared code snippet of the internal implementation of the SaveEmailAddressTask along with the code implementation of a demo app.

Today in this blog post, we will learn how to compose an email using the Windows Phone 7 SDK class called "EmailComposeTask". I will also be sharing the decompiled version of the class, so that you can know the SDK implementation. Continue reading and at the end, don’t forget to leave your feedback.

Know About the API

Like all other launchers and choosers, "EmailComposeTask" is also a sealed class present inside the namespace Microsoft.Phone.Tasks. It exposes few properties to populate the email fields like "To", "Cc", "Bcc", "Subject", "Body", etc. The one and only one method named "Show()" opens up the Email Composer dialog in the screen.

Here is the meta data of the EmailComposeTask class:

namespace Microsoft.Phone.Tasks
    public sealed class EmailComposeTask
        public string Body { get; set; }
        public string Bcc { get; set; }
        public string Cc { get; set; }
        public int? CodePage { get; set; }
        public string Subject { get; set; }
        public string To { get; set; }
        public void Show();

Do you want to know how this class has been implemented inside the SDK library? Then here is your chance to study the code. I am sharing the decompiled version of the EmailComposeTask class here:

namespace Microsoft.Phone.Tasks
    public sealed class EmailComposeTask
        private const int SHAREMETHOD_SEND = 1;
        private const string AppUri = "app://5B04B775-356B-4AA0-AAF8-6491FFEA5614/ShareContent";

        public string Body { get; set; }
        public string Bcc { get; set; }
        public string Cc { get; set; }
        public int? CodePage { get; set; }
        public string Subject { get; set; }
        public string To { get; set; }

        public void Show()
        if (!ChooserHelper.NavigationInProgressGuard((Action) (() => this.Show())))
            ChooserHelper.Navigate(new Uri(this.BuildUri(), 
                  UriKind.Absolute), this.BuildParameterPropertyBag());

        internal string BuildUri()
            return "app://5B04B775-356B-4AA0-AAF8-6491FFEA5614/ShareContent";

        internal ParameterPropertyBag BuildParameterPropertyBag()
            ParameterPropertyBag parameterPropertyBag = new ParameterPropertyBag();
            if (!string.IsNullOrEmpty(this.To))
                parameterPropertyBag.CreateProperty("To").StringValue = this.To;
            if (!string.IsNullOrEmpty(this.Cc))
                parameterPropertyBag.CreateProperty("Cc").StringValue = this.Cc;
                string subject = this.Subject;
            if (!string.IsNullOrEmpty(subject))
                parameterPropertyBag.CreateProperty("Subject").StringValue = subject;
                string body = this.Body;
            if (!string.IsNullOrEmpty(body))
                parameterPropertyBag.CreateProperty("Body").StringValue = body;
                string bcc = this.Bcc;
            if (!string.IsNullOrEmpty(bcc))
                parameterPropertyBag.CreateProperty("Bcc").StringValue = bcc;
                int? codePage = this.CodePage;
            if (codePage.HasValue)
                parameterPropertyBag.CreateProperty("CodePage").StringValue = codePage.Value.ToString();
                parameterPropertyBag.CreateProperty("ShareMethod").Int32Value = 1;
                parameterPropertyBag.CreateProperty("MsgClass").StringValue = "IPM.Note";
                return parameterPropertyBag;

Here, the internal method named BuildParameterPropertyBag() constructs all the properties to compose the email. Check out the AppUri that the class generates.

Implementation Steps

Now, it’s time to demonstrate the implementation to compose an email from the code. The exposed properties allow you to auto populate the values. Based on your requirement, set the required properties as shown below:

var emailComposeTask = new EmailComposeTask
    To = "",
    Cc = ";",
    Bcc = "",
    Subject = "Test Message using EmailComposeTask",
    Body = "This is a test email body created using the EmailComposeTask"

At the end, call the Show() method to open the composer task. If you have multiple email accounts setup in your phone device, this will ask you to chose the right account. Otherwise, it will directly go to the next screen where the UI will have an email client showing the email compose screen. User will be able to add/update any field from the screen.

Note: The WP7 emulator doesn't provide setting up email account and hence I am unable to provide screenshot here.

I hope that this post was very useful for you to understand the SDK API, it’s internal code implementation and the sample code implementation. Please leave your feedback below to leave your comment.

Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletters to your registered email address. We will not share your email address with anybody as we respect your privacy.


You may like to follow me on twitter @kunal2383 or may like the Facebook page of my blog


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Technical Blog:
Twitter :

You may also be interested in...


Comments and Discussions

QuestionAdd any kind of attachment or send unattended (without EmailComposeTask) Pin
Member 151651111-Jan-13 14:51
memberMember 151651111-Jan-13 14:51 
GeneralMy vote of 1 Pin
Selvin19-Apr-12 22:49
memberSelvin19-Apr-12 22:49 
AnswerRe: My vote of 1 Pin
_ Kunal Chowdhury _6-May-12 18:45
mvp_ Kunal Chowdhury _6-May-12 18:45 
Hi Selvin,

This could not be an interesting topic to you, but if you read this series, I clearly mentioned that the series will include the decompiled version of the API and the small implementation steps so that a poor novice can learn it easily.

A developer not only needs code for implementation, he should know how the SDK code has been implemented too. This will give better visibility of the APIs to them. And yes, every thing is now available online in MSDN, then as per your feedback no one should share the same thing in book or weblog. D'Oh! | :doh: My article series are not just code bunch copied from MSDN. They are easy enough for a poor novice to bring into the expert level. No one can happy the other one as much as he provides but if my article helps at least 1 person, that's more than enough for me.

I hope, you can understand my points.
Regards - Kunal Chowdhury
Microsoft MVP (Silverlight) | Codeproject MVP & Mentor | Telerik MVP

Follow me on: My Technical Blog | Silverlight-Zone | Twitter | Facebook | Google+

QuestionAbout email accounts Pin
Pete O'Hanlon19-Apr-12 4:45
protectorPete O'Hanlon19-Apr-12 4:45 
AnswerRe: About email accounts Pin
_ Kunal Chowdhury _19-Apr-12 5:12
mvp_ Kunal Chowdhury _19-Apr-12 5:12 
GeneralRe: About email accounts Pin
Pete O'Hanlon19-Apr-12 5:38
protectorPete O'Hanlon19-Apr-12 5:38 
GeneralRe: About email accounts Pin
_ Kunal Chowdhury _19-Apr-12 5:54
mvp_ Kunal Chowdhury _19-Apr-12 5:54 
SuggestionFormatting Pin
Mika Wendelius18-Apr-12 17:26
mvpMika Wendelius18-Apr-12 17:26 
GeneralRe: Formatting Pin
_ Kunal Chowdhury _18-Apr-12 18:05
mvp_ Kunal Chowdhury _18-Apr-12 18:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170622.1 | Last Updated 19 Apr 2012
Article Copyright 2012 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid