Skip to content

Instantly share code, notes, and snippets.

@ChrisMash
Last active April 9, 2023 02:19
Show Gist options
  • Save ChrisMash/e1630095a9cabf766c70bb5573d726fa to your computer and use it in GitHub Desktop.
Save ChrisMash/e1630095a9cabf766c70bb5573d726fa to your computer and use it in GitHub Desktop.
Send an email using the user's chosen default email app (e.g. Mail, Gmail, Outlook etc.) instead of using MFMailComposeViewController that requires the Mail app to be setup with an account
let address = "[email protected]"
let subject = "AwesomeApp Feedback"
// Example email body with useful info for bug reports
let body = "\n\nApp Version: \(appVersion)\nDevice: \(deviceType)\niOS: \(osVersion)"
// Build the URL from its components
var components = URLComponents()
components.scheme = "mailto"
components.path = address
components.queryItems = [
URLQueryItem(name: "subject", value: subject),
URLQueryItem(name: "body", value: body)
]
guard let url = components.url else {
NSLog("Failed to create mailto URL")
return
}
UIApplication.shared.open(url) { success in
// handle success or failure
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment