Freigeben über


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

Comments

  • Anonymous
    December 30, 2014
    it gives the following error Error 1 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. c:usersamoldocumentsvisual studio 2013projectsapp5app5aboutus.xaml.cs 139 1 App5

  • Anonymous
    January 10, 2015
    Thankyou. It was very helpful.

  • Anonymous
    January 12, 2015
    Amol, that is correct, you simply need to wrap the code provided in a method marked as async.