Check This how to send email through Windows Phone 8 application??
In visual studio 2012
1. Create new Xaml file Name MainPage.Xaml
2. Paste the following
XAML CODE:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" x:Name="btnSaveEmailAddress" Content="Save Email Address"
Click="btnSaveAddress_Click" />
<Button Grid.Row="1" x:Name="btnChooseEmailAddress" Content="Choose Email Address" Click="btnChooseEmailAddress_Click"/>
<Button Grid.Row="2" x:Name="btnComposeEmail" Content="Compose Email" Click="btnComposeMail_Click" />
</Grid>
</Grid>
Right Click MainPage.Xaml and select View Code in that MainPage.Xaml.cs Paste the following codes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WP8EmailTasksDemo.Resources;
using Microsoft.Phone.Tasks;
namespace WP8EmailTasksDemo
{
public partial class MainPage : PhoneApplicationPage
{
SaveEmailAddressTask saveEmailAddressTask;
EmailAddressChooserTask emailAddressChooserTask;
// Constructor
public MainPage()
{
InitializeComponent();
this.emailAddressChooserTask = new EmailAddressChooserTask();
this.emailAddressChooserTask.Completed += new EventHandler<EmailResult>(emailAddressChooserTask_Completed);
this.saveEmailAddressTask = new SaveEmailAddressTask();
this.saveEmailAddressTask.Completed += new EventHandler<TaskEventArgs>(saveEmailAddressTask_Completed);
}
private void btnSaveAddress_Click(object sender, RoutedEventArgs e)
{
saveEmailAddressTask.Email = "testmail@test.com";
saveEmailAddressTask.Show();
}
private void saveEmailAddressTask_Completed(object sender, TaskEventArgs e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show("Email successfully Saved..");
}
}
private void btnChooseEmailAddress_Click(object sender, RoutedEventArgs e)
{
emailAddressChooserTask.Show();
}
private void emailAddressChooserTask_Completed(object sender, EmailResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show("Selected email :" + e.Email);
}
}
private void btnComposeMail_Click(object sender, RoutedEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.To = "chris@example.com";
emailComposeTask.To = saveEmailAddressTask.Email;
emailComposeTask.Body = "WP8 Emails Demo";
emailComposeTask.Cc = "testmail2@test.com";
emailComposeTask.Subject = "Windows Phone 8";
emailComposeTask.Show();
}
}
}
enjoy the code.......