Thursday, August 21, 2014

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:


EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "Subject";
emailComposeTask.To = "";

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


// Define Recipient
EmailRecipient sendTo = new EmailRecipient()
    Name = "Name of Recepient",
    Address = ""

// 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

// Open the share contract with Mail only:
await EmailManager.ShowComposeNewEmailAsync(mail);

Have fun,
Paras Wadehra
Microsoft MVP - Windows Platform Development
My WP Apps

Saturday, August 2, 2014

Xamarin Forms Shared project template error

The new Xamarin Forms Shared Project Template has a bug which causes the Windows Phone build to fail out of the box. You might see an error like:

The 'ProductID' attribute is invalid - The value 'b79569cb-1898-4dab-9173-afe40fa8559c' is invalid according to its datatype 'http://WPCommontypes:ST_Guid' - The Pattern constraint failed.

Note that the error message you receive might be a little different depending on what value is not defined properly. You are in luck though, as there is a simple fix for this.

You can fix the issue by modifying the WMAppManifest.xml file in your Windows Phone project. You need to add curly braces (are there any other style?) around the GUID values for the ProductID and PublisherID attributes. In some cases there might be other GUID values that are missing the curly braces too so add them there as well.

And that's it! This should resolve your error and get you on your path to a successfully building application :)

Paras Wadehra
Microsoft MVP - Windows Platform Development
My WP Apps