Last active
April 9, 2023 02:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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