Thursday, April 4, 2024

Open default email app in .NET MAUI

Sample Code:

 if (Email.Default.IsComposeSupported)

{

    string subject = "Hello!";

    string body = "Excellent!";

    string[] recipients = new[] { "Support@3MbSolutions.com", "Marketing@3MbSolutions.com" };


    var message = new EmailMessage

    {

        Subject = subject,

        Body = body,

        BodyFormat = EmailBodyFormat.PlainText,

        To = new List<string>(recipients)

    };


    await Email.Default.ComposeAsync(message);

}

If your project's Target Android version is set to Android 11 (R API 30) or higher, you must update your Android Manifest with queries that use Android's  package visibility requirements.

In the Platforms/Android/AndroidManifest.xml file, add the following queries/intent nodes in the manifest node:

<queries>

  <intent>

    <action android:name="android.intent.action.SENDTO" />

    <data android:scheme="mailto" />

  </intent>

</queries>


No comments:

Post a Comment

How to add the .NET MAUI App Accelerator in Visual Studio

 To add the .NET MAUI App Accelerator in Visual Studio, follow these steps: Prerequisites: Ensure you have Visual Studio 2022 (17.3 or lat...