Goodbye MFMailComposeViewController?

For many years I’ve used MFMailComposeViewController in my iOS apps to help the user send feedback emails to me. It’s a nice way of keeping the user in my app and just popping up an email composition sheet to let them say whatever they want to say quickly and easily.

This approach uses the Mail app of iOS, provided by Apple, which would generally be setup with a user’s iCloud email account and any others they’ve setup in the app themselves.

But it’s entirely possible that a user doesn’t have an email account setup in the Mail app. Maybe they have a preferred app they use like Gmail, Outlook etc. If that’s the case you’d just get an error from MFMailComposeViewController that it wasn’t possible to send an email with it.

In the past I’d always taken the easy way out and just displayed an alert saying the email couldn’t be created and listed my email address so they could go off to their alternative email app to write their feedback. I would sometimes even copy my email address to the pasteboard so they could easily paste it into their email app rather than having to memorise it.

Since iOS 14 a user has been able to setup a preferred default email app, which will then be opened for any email related OS functionality, rather than the Mail app. So a better approach is to go back in time and use the old classic mailto: URL and ask iOS to to find the right app to handle it, i.e. the default email app they’ve selected.

Here’s a code example showing you can do this with a predefined subject and body for the email:

Example code for sending an email via mailto:

Simple as that! Your users have less friction to get in touch with you if they’re not using the Mail app so you’re that little bit more likely to get any feedback they want to share with you.

You can read up more on other options for mailto: URLs here.

With only the mailto: approach you do lose the benefit of keeping the user in your app, so if they want to continue using your app they need to find their way back, which for less experienced users could be confusing of course.

You could keep using MFMailComposeViewController by default and just fallback to mailto: if the Mail app isn’t setup, though that would ignore the user’s preference of using a different email app, which is could send them into a fit of rage! It unfortunately doesn’t seem like there’s any way to determine whether the user has a default email app that’s not the Mail app setup, based on this Stackoverflow question.