Compose an Email in Windows 10

Here we are going to compose an email from a Universal App with email compose class.

Step 1: Open a blank window and add the following fields either by using toolbox or by copying the following XAML code to your grid.

  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="to" 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="cc" 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 2:
Copy and paste the following code to the cs page which will handle each event assigned to the Send Button.
  1. private async void sendEmail_Click(object sender, RoutedEventArgs e)  
  2. {  
  3.     EmailMessage email = new EmailMessage();  
  4.     email.To.Add(new EmailRecipient(to.Text));  
  5.     email.CC.Add(new EmailRecipient(cc.Text));  
  6.     email.Subject = subject.Text;  
  7.     email.Body = body.Text;  
  8.     await EmailManager.ShowComposeNewEmailAsync(email);  
  9. }  
Step 3: Run and test your application.