UWP mail API - from non-UWP project (but desktop-bridge)


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

What I found is that:

  • UWP exposes new mail API
  • Any application referencing some WinRT DLLs (my app is WPF Windows Desktop application) can use the new UWP APIs (including the new mail API). (Btw. UWP anf WPF UI is not compatibile - but this is different story and we are not dealing with this (cross platform UI usage) here)

I've already made some successfull tests with light sensor (UWP APIs consumed from Windows console application), and hoped the mail api will work as well. However, when I run this simple code - it works when compiled in UWP project, however it does not, when run from within WPF application.

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, that mail api exposed by UWP will not work from WPF (or any non-UWP host) ? Can anyone tell whether it is general behavior and not specific to my environment ? (in order to compile in WPF project, need to add reference to two DLLs: System.runtime.windowsruntime.dll and Windows.winmd)

I tried to call the UWP mail api both from "raw" WPF application, and also having packaged it and installed as Windows Desktop UWP application - I get the same negative result.

Only when run from UWP application the code shows mail client

Thanks in advance, Michal

asked on Stack Overflow Sep 22, 2017 by Michal.Jan008

2 Answers


Can you use URI? I think more app support URI but they don't support uwp mail protocol.

I will tell you an easy way to send the email with URI.

I write a function that can help to send the email.

    private async Task UniversallyEmail(string email, string subject, string messageBody)
        messageBody = Uri.EscapeDataString(messageBody); 
        string url = $"mailto:{email}?subject={subject}&body={messageBody}";
        await Launcher.LaunchUriAsync(new Uri(url));

I think it's easy to use.

answered on Stack Overflow Sep 23, 2017 by lindexi

I've learned that particularly the Windows.ApplicationModel.Email APIs are not currently supported in this scenario. https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-supported-api

answered on Stack Overflow Sep 23, 2017 by Michal.Jan008

User contributions licensed under CC BY-SA 3.0