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:
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
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.
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
User contributions licensed under CC BY-SA 3.0