Search code examples
mauimaui-windows

Email in .Net MAUI on Windows is supported, but throws an exception


I have a .Net MAUI app. I have the following code to send emails (taken from https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/communication/email?view=net-maui-7.0&tabs=windows):

        try
        {
            if (Microsoft.Maui.ApplicationModel.Communication.Email.Default.IsComposeSupported)
            {
                var message = new EmailMessage
                {
                    Subject = string.Empty,
                    Body = string.Empty,
                    BodyFormat = EmailBodyFormat.PlainText,
                    To = new List<string>() { _emailTechService },
                };

                await Email.Default.ComposeAsync(message);
            }
            else
            {
                await Shell.Current.DisplayAlert("Email Failure", $"Sending emails feature is not supported on this device", "OK");
            }
        }
        catch (Exception ex)
        {
            App.HandleException(ex, true);
        }

On iOS and Android it works correctly, but when I run it on Windows Machine in Visual Studio, IsComposeSupported is true, but Email.Default.ComposeAsync(message) throws a System.Runtime.InteropServices.COMException "The request is not supported."

How can I check if the feature is supported correctly to avoid the exception?


Solution

  • This is an existed issue on the github. You can check the issue which is about Sending e-mail works in Android but not in Windows.

    It used the same code as yours and met the same error. According to the comment in it, the cause is the issue for the WinUI. You can follow up it on the github.