iOS Email composing crashes App
See original GitHub issueDescription
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
- Create a maui App
- try to send an Email using the Email Api on a physical iOS device
- 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:
- Created 9 months ago
- Comments:15 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.cominstead ofmailto:email@domain.comand 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 withmailto:protocol.@samhouts it must be backported to .NET 7