In this how to tutorial we are going to see important and more useful task on composing an email using the Launchers that are available as part of the Windows Phone. To get some clear idea on Launchers and list of Launchers check this article on Working with Launchers in WP7. Email Compose Task provides the application to launch the email application and opts to enter a new mail message. We can play around with providing the different options like having the recipients name, Email id, subject, to, cc, bcc etc. Once we are done with the required options the email will be send on clicking of the send button which will be available as part of the Email application. [more]
Let us see the different code on how to make use of the Email Compose Task in Windows Phone development.
Open Visual Studio 2010 IDE and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below. Once the project is created add some controls which are used to trigger the Email Compose task.
Now let us make some changes to the UI, which on button clicks will launch the Email Message application. We are going to add a button which will trigger the email compose task. Once we added the button in the code behind we need to start with the code. Email Compose task has the assembly Microsoft.Phone.Task as the namespace, which is needed to be added in the using statement as below code
using Microsoft.Phone.Tasks;
Microsoft.Phone.Task.EmailComposeTask has the below set of properties which are used to play around with the email message sending application basically creates a new Email Message and send it across to different recipients
Properties:
S No |
Property Name |
Description |
1 |
TO |
Recipients address to be specified here |
2 |
CC |
If required to have a Carbon Copy (CC) to any Recipients |
3 |
BCC |
If required to have a Blind Carbon Copy (BCC) to any Recipients |
4 |
BODY |
Email message |
5 |
SUBJECT |
Email Subject Line |
6 |
CODEPAGE |
Character Set to display the message content |
Now in the button click event we need to play around with the code as shown below.
Code:
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
namespace F5debugWp7EmailComposeTask
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
EmailComposeTask f5EmailCompose = new EmailComposeTask();
f5EmailCompose.To = “Karthikeyan@f5debug.net”;
f5EmailCompose.Subject = “F5Debug Tutorial”;
f5EmailCompose.Body = “EMail Compose Task Sample Application”;
f5EmailCompose.Show();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
EmailComposeTask f5EmailCompose = new EmailComposeTask();
f5EmailCompose.To = “Karthikeyan@f5debug.net”;
f5EmailCompose.Subject = “F5Debug Tutorial”;
f5EmailCompose.Body = “EMail Compose Task Sample Application”;
f5EmailCompose.Cc = “KarthikCC@f5debug.net”;
f5EmailCompose.Show();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
EmailComposeTask f5EmailCompose = new EmailComposeTask();
f5EmailCompose.To = “Karthikeyan@f5debug.net”;
f5EmailCompose.Subject = “F5Debug Tutorial”;
f5EmailCompose.Body = “EMail Compose Task Sample Application”;
f5EmailCompose.Bcc = “KarthikBCC@f5debug.net”;
f5EmailCompose.Show();
}
}
}
Now we are done with our code, just run the application and we can see the expected output as shown below. Basically we will not have option to test with the emulator as the emulator will prompt to set the internet to sent the message. So we can set up the account and then try to use the code which will send the mail accordingly.
Output:
No Comments
Hi, Where is Emailcomposetask completed event?
how can we know that the mail has been sent?
for those who is still not reading this article…i may say… dont waste your time for some trash article…this article is worth of your time…