Build Simple Email App In Universal Windows App(UWP)

Prerequisites

  • Visual Studio 2015

Now, let's get started with the following steps.

Step 1 - Create Windows Universal Project

Open Visual Studio 2015 and Click File -> New -> Project Option for New Universal App.



Step 2 - Giving the Project Name

Then, New Project window will open. There, select Installed -> Template -> Visual C# -> Windows -> Universal and select a Blank App (Universal Windows).

Type the Project Name as ComposeEmail and click OK.



Step 3 - Setting the platform versions

Here, we choose the Target Version and Minimum Version for our Universal Windows application, and click OK.



Step 4 - Choose Designer Window

Now, go to the Solution Explorer and select MainPage.xaml.



Step 5 - Designing the App

In the MainPage.xaml designing page, to compose email app, we need 5 TextBlock, 4 Textbox, and one Command Button. So, add 5 TextBlocks and change the Text property in the Properties Window (See the below table).

Control Name Text Property
TextBlock1 Compose Mail
TextBlock2 To
TextBlock3 CC
TextBlock4 Subject
TextBlock5 Body

Next, add 4 Textboxes and one Button control, and change their Name property in the Properties Window (See the below table).

Control Name Name Property
Textbox1 tomail
Textbox2 ccmail
Textbox3 Subject
Textbox4 Body
Button1 SendEmail



XAML code

  1. <Grid.ColumnDefinitions>  
  2.     <ColumnDefinition Width="Auto"></ColumnDefinition>  
  3.     <ColumnDefinition Width="*"></ColumnDefinition>  
  4. </Grid.ColumnDefinitions>  
  5. <Grid.RowDefinitions>  
  6.     <RowDefinition Height="Auto"></RowDefinition>  
  7.     <RowDefinition Height="Auto"></RowDefinition>  
  8.     <RowDefinition Height="Auto"></RowDefinition>  
  9.     <RowDefinition Height="Auto"></RowDefinition>  
  10.     <RowDefinition Height="Auto"></RowDefinition>  
  11.     <RowDefinition Height="Auto"></RowDefinition>  
  12. </Grid.RowDefinitions>  
  13. <TextBlock Text="Compose Mail" FontSize="25" Grid.Row="0" FontWeight="Bold"></TextBlock>  
  14. <TextBlock Margin="5,10,0,0" Text="To" Grid.Row="1" FontSize="20"></TextBlock>  
  15. <TextBox Margin="0,10,10,0" Name="tomail" Grid.Column="1" Grid.Row="1"></TextBox>  
  16. <TextBlock Margin="5,10,0,0" Text="CC" Grid.Row="2" FontSize="20"></TextBlock>  
  17. <TextBox Margin="0,10,10,0" Name="ccmail" Grid.Column="1" Grid.Row="2"></TextBox>  
  18. <TextBlock Margin="5,10,0,0" Text="Subject" Grid.Row="3" FontSize="20"></TextBlock>  
  19. <TextBox Margin="0,10,10,0" Name="subject" Grid.Column="1" Grid.Row="3"></TextBox>  
  20. <TextBlock Margin="5,10,0,0" Text="Body" Grid.Row="4" FontSize="20"></TextBlock>  
  21. <TextBox Margin="0,10,10,0" Name="body" Grid.Column="1" Grid.Row="4" Height="100" TextWrapping="Wrap"></TextBox>  
  22. <Button Margin="0,10,10,0" HorizontalAlignment="Right" Content="Send" Name="sendEmail" Grid.Column="1" Grid.Row="5" Click="sendEmail_Click"></Button>  
Step 6 - Add the Coding

To add the coding, we need to add the following namespace in MainPage.xaml.cs page.



Then, write the below code for Save button.
  1. private async void sendEmail_Click(object sender, RoutedEventArgs e)   
  2. {  
  3.     EmailMessage email = new EmailMessage();  
  4.     email.To.Add(new EmailRecipient(tomail.Text));  
  5.     email.CC.Add(new EmailRecipient(ccmail.Text));  
  6.     email.Subject = subject.Text;  
  7.     email.Body = body.Text;  
  8.     await EmailManager.ShowComposeNewEmailAsync(email);  
  9. }  
Step 7 - Run the Application

Now, we are ready to run our project. So, click the Local Machine for running the application.


Conclusion - I hope you understood how to compose an email in Universal Windows Platform.

 

Up Next
    Ebook Download
    View all
    Learn
    View all