How to launch the iOS mail app in Swift?

Obviously a few years later...I had to add a completion handler for Xcode 10.2.1 swift 5.

This works perfectly-

    let emailURL = NSURL(string: "message://")!

    if UIApplication.shared.canOpenURL(emailURL as URL)
    {
        UIApplication.shared.open(emailURL as URL, options: [:],completionHandler: nil)
    }

The Swift 3.0.1 way of just opening the Mail app goes as follows:

private func openMailClient() {
    let mailURL = URL(string: "message://")!
    if UIApplication.shared.canOpenURL(mailURL) {
        UIApplication.shared.openURL(mailURL)
    }
}

As "dehlen" correctly stated, using the message:// scheme will only open the mail app, if no further information is provided.


Not tested myself but maybe this answer will help you:

Apparently Mail supports a second url scheme message:// which (I suppose) allows you to open a specific message if it was fetched by your application. If you do not provide a full message url, it will just open Mail:

let mailURL = URL(string: "message://")!
if UIApplication.shared.canOpenURL(mailURL) {
    UIApplication.shared.openURL(mailURL)
}

Taken from: Launch Apple Mail App from within my own App?