How do I run showComposeNewEmailAsync from main method

0

I am trying to run the following function: https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.email.emailmanager.showcomposenewemailasync

First of all I do not know much about async programming or even C# but need to run this method desperately so might need a bit more help here. from my main method. I currently have:

    static void Main(String[] args) {
        EmailMessage email = new EmailMessage();
        await EmailManager.ShowComposeNewEmailAsync(email);
    }

But I get an error stating:

Program.cs(26,4): error CS4033: The 'await' operator can only be used within an async method. Consider marking this m ethod with the 'async' modifier and changing its return type to 'Task'. [C:\Projects\C\UapHello\uaphello.csproj]

Any help will be welcome. Thank you

UPDATE:

I have had some luck running the method using:

    static void Main(String[] args) {
        // emailmessage
        EmailMessage email = new EmailMessage();
        Task.Run(async () => { await EmailManager.ShowComposeNewEmailAsync(email); }).Wait();
    }

Unfortunately, when I run it, I get the error message:

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.Exception: The request is not supported. (Exception from HRESULT: 0x80070032) at Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(EmailMessage message) at uaphello.Program.<>c__DisplayClass0_0.<b__0>d.MoveNext() in C:\Projects\C\UapHello\Program.cs:line 18 --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at uaphello.Program.Main(String[] args) in C:\Projects\C\UapHello\Program.cs:line 18

I am basically trying to open the default mail application with an attachment in windows 10. My idea is to create an exe file to do this, since my main app is an electron app, which does not have access to uwp api's. Thanks.

c#
asked on Stack Overflow Jul 7, 2019 by daibatzu • edited Jul 7, 2019 by daibatzu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0