Consuming UWP mail api from WPF Desktop Bridge App

Elvis Xia 131 Reputation points Microsoft Employee
2019-10-30T06:17:48.137+00:00

I'm porting my WPF application to UWP, but some APIs are not permitted in the UWP - one of these is classic mail API (MAPI).

I've already made some successfull tests about consuming UWP APIs from Desktop Application and hoped the mail api will work as well. However, when I run the following simple code - it works when compiled in UWP project, but it does not work when run within the WPF application. I have also packaged it and installed as Windows Desktop UWP application by using the Desktop Bridge, but it does not work as well.

EmailMessage emailMessage = new EmailMessage();  
emailMessage.To.Add(new EmailRecipient("someone@gmail.com"));  
emailMessage.Body = "message body";  
await EmailManager.ShowComposeNewEmailAsync(emailMessage);  

When run it ends up with communicate: The request is not supported Exception from hresult (0x80070032)

The question is: Is this a known limitation? Can anyone tell whether it is general behavior and not specific to my environment?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 33,371 Reputation points Microsoft Vendor
    2019-10-30T07:54:19.04+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    Yes, this is the expected behavior.

    Windows.ApplicationModel.Email is not supported in desktop apps and is not on the list of API supported in a packaged desktop app.

    For more information, please check the following article:

    UWP APIs available to desktop apps:
    https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-supported-api

    In order to implement your requirement, you may need to include both a UWP and a desktop app in your package and call the email API from the UWP side. Please check the following articles to the get start:

    App Service:
    https://learn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service

    App Service Destop Bridge sample:
    https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample.

    Thanks.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.