1

Following the documentation from Apple, I was able to successfully pop the MFMailComposeViewController modal up with prefilled email recipients. Well, until I tried to prefil the modal with an internationalized email address with non-ascii characters:

    let picker = MFMailComposeViewController()
    picker.setToRecipients(["eai-testé@domain.tld"])
    // ...

Surprisingly, when I input the non-ascii email manually, there is no problem with the mail native app. I successfully find a programmatical ugly workaround:

        var email = "eai-testé@domain.tld".addingPercentEncoding(withAllowedCharacters: .alphanumerics)
    var str = "mailto:" + email.unsafelyUnwrapped
    UIApplication.shared.openURL(URL(string: str).unsafelyUnwrapped)

This method won't work with the MFMailComposeViewController since it uses url encoding, which does not make sense for a plain email address. Of course, not using MFMailComposeViewController isn't good, since the workaround doesn't have a predicate to intercept errors and stuff like that.

1
  • 1
    RFC6531 is not widely adopted. That having being said, I agree that if we can enter it manually, we should be able to do programmatically with via MFMailComposeViewController, too. Now, whether our mail servers support it or not is a separate question...
    – Rob
    Sep 16, 2021 at 19:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.