question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS Email composing crashes App

See original GitHub issue

Description

I am sending an email using the Email.Default.ComposeAsync() method

this works fine on Android but crashes on iOS with the exception below

2022-12-09 19:19:10.850 ClientUI[11511:2319672]    at System.Uri..ctor(String uriString, UriKind uriKind)
   at Foundation.NSUrl.op_Implicit(NSUrl url)
   at Microsoft.Maui.ApplicationModel.Communication.EmailImplementation.ComposeWithUrl(EmailMessage message)
2022-12-09 19:19:10.850 ClientUI[11511:2319672]    at Microsoft.Maui.ApplicationModel.Communication.EmailImplementation.PlatformComposeAsync(EmailMessage message)
   at Microsoft.Maui.ApplicationModel.Communication.EmailImplementation.ComposeAsync(EmailMessage message)

here is the code that send the email

if( Email.Default.IsComposeSupported )
        {
          string username = name;
          if( string.IsNullOrEmpty( username ) )
          {
            username = "Unknown";
          }

          string subject = $"Wi-Fi Messenger Logs for client <{username}>";
          string body = $"Attached is the zipped up log files for client <{username}>";
          string targetName = Path.Combine( TARGET_PATH,
                                            MakeValidFileName( $"{username}_{DateTime.UtcNow:yyyy-MM-dd_hh-mm-ss}.zip" ) );

          using FileStream targetFile = File.OpenWrite( targetName );
          //Emails require the zip file be in an actual file
          outputMemStream.WriteTo( targetFile );
          targetFile.Close();

          EmailMessage message = new()
          {
            Subject = subject,
            Body = body,
            BodyFormat = EmailBodyFormat.PlainText,
            Attachments = new List<EmailAttachment>() { new EmailAttachment( targetName ) },
            To = new List<string>() { recipient.Trim() }
          };

          await Email.Default.ComposeAsync( message );

I have added this to my info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>mailto</string>
</array>

Steps to Reproduce

  1. Create a maui App
  2. try to send an Email using the Email Api on a physical iOS device
  3. Observe the crash

Link to public reproduction project repository

N/A

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16.1.2

Did you find any workaround?

No response

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ritesh-burncommented, Feb 16, 2023

It looks like the relevant code that crashes is this line: https://github.com/dotnet/maui/blob/main/src/Essentials/src/Email/Email.shared.cs#L81 It sets the url to something like mailto:email%40domain.com instead of mailto:email@domain.com and that causes the https://github.com/dotnet/maui/blob/main/src/Essentials/src/Email/Email.ios.cs#L90 line to throw an exception as its not a valid url with mailto: protocol.

1reaction
ederbondcommented, Apr 4, 2023

@samhouts it must be backported to .NET 7

Read more comments on GitHub >

github_iconTop Results From Across the Web

mail crashes when trying to open a draft
Just start to compose another email and swipe it down to obtain a second draft (in addition to the one that's crashing). When...
Read more >
4 Tips to Fix iPhone Mail App Crashing in iOS 15/14/13/12/11
Part 1. Mail app crashing when composing a new email · Force shut the mail application and restart your iPhone. · Within the...
Read more >
After iOS 16 Update, Mail App is Crashing (Works on 16.5 ...
The proprietary Mail app on the iPhone and iPad crashed after the iOS 16 update. Users have complained about the random crash.
Read more >
iOS 16 mail app crashes when it receives an email
There is a new bug in the iOS 16 system that causes the mail application to crash. This happens when the incoming email...
Read more >
How to fix Mail for iOS app glitches and crashes
Mail for iPhone keeps crashing: Mail crashes when composing new emails · Force quit the Mail app and restart your iPhone/iPad · Disable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found