I've been trying to invoke a UWP mail app
from my WinForms (desktop) app using this example.
I understand that I'm doing it from a desktop app, but there seems to be ways to allow it in the latest versions of Windows 10: here and here.
My goal is to be able to start a Windows 10 built in Mail app and have it open up a new email message with my subject line, message and attachment already pre-filled. (Kinda like what MAPI used to be able to do.)
But so far, if I do this from my WinForms C# app:
private void sendEmailAsync()
{
var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();
emailMessage.Body = "This is a message body";
emailMessage.To.Add(new EmailRecipient("someone@gmail.com"));
emailMessage.Subject = "My subject";
StorageFile file = await StorageFile.GetFileFromPathAsync(@"path-to\attachment-file.txt");
emailMessage.Attachments.Add(new EmailAttachment(@"attachment.txt", file));
WaitForAsync(Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage));
}
void WaitForAsync(IAsyncAction A)
{
while(A.Status == AsyncStatus.Started)
{
Application.DoEvents();
System.Threading.Thread.Sleep(1);
}
}
The call to ShowComposeNewEmailAsync
throws the exception: "HRESULT: 0x80070032 The request is not supported."
So how can I make it work?
User contributions licensed under CC BY-SA 3.0