question

elvisxia avatar image
3 Votes"
elvisxia asked ·

Consuming UWP mail api from WPF Desktop Bridge App


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?

windows-uwpwindows-uwp-runtimewindows-desktop-bridge
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RoyLi-MSFT avatar image
2 Votes"
RoyLi-MSFT answered ·

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://docs.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://docs.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.


· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The MailKit library will be a good choice. The dotnet/platform-compat on github suggests you to use MailKit. It's an open source library. It supports .NET 4.5, .NETStandard 1.3/1.6/2.0, Windows Universal 8.1, Xamarin.Android, and Xamarin.iOS.


0 Votes 0 · ·