How to send email from your Windows Phone 8.1 app

As part of the API changes made in the new Windows Phone 8.1 XAML programming model, the EmailComposeTask - and several other tasks - that were available in the Microsoft.Phone.Tasks namespace in Windows Phone 8 are no longer available.

Most of these have been replaced with a new way of performing the same tasks. For sending an email from within your app, the old way in Windows Phone 8 was as follows:

OLD WAY
========

EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "Subject";
emailComposeTask.To = "support@developer.com";
emailComposeTask.Show();

 

The new way in Windows Phone 8.1 to send an email from your app is as follows:

 

NEW WAY
=========

 

// Define Recipient

EmailRecipient sendTo = new EmailRecipient()

{

    Name = "Name of Recepient",

    Address = "support@developer.com"

};

 

// Create email object

EmailMessage mail = new EmailMessage();

mail.Subject = "this is the Subject";

mail.Body = "this is the Body";

 

// Add recipients to the mail object

mail.To.Add(sendTo);

//mail.Bcc.Add(sendTo);

//mail.CC.Add(sendTo);

 

// Open the share contract with Mail only:

await EmailManager.ShowComposeNewEmailAsync(mail);

 
 
Have fun,
Paras Wadehra
Microsoft MVP - Windows Platform Development
https://twitter.com/ParasWadehra
https://www.facebook.com/WindowsPhoneDeveloper
My WP Apps

 

 

 

Via Blogspot