Launch Apple Mail App from within my own App?
Apparently Mail application supports 2nd url scheme - message://
which ( I suppose) allows to open specific message if it was fetched by the application. If you do not provide message url it will just open mail application:
NSURL* mailURL = [NSURL URLWithString:@"message://"];if ([[UIApplication sharedApplication] canOpenURL:mailURL]) { [[UIApplication sharedApplication] openURL:mailURL];}
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";NSString *body = @"&body=It is raining in sunny California!";NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
Swift version of the original Amit's answer:
Swift 2:
func openMailApp() { let toEmail = "email@outlook.com" let subject = "Test email".stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet() let body = "Just testing ...".stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet() if let urlString = ("mailto:\(toEmail)?subject=\(subject)&body=\(body)")), url = NSURL(string:urlString) { UIApplication.sharedApplication().openURL(url) }}
Swift 3.0:
func openMailApp() { let toEmail = "email@outlook.com" let subject = "Test email".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) let body = "Just testing ...".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) if let urlString = "mailto:\(toEmail)?subject=\(subject)&body=\(body)", let url = URL(string:urlString) { UIApplication.shared().openURL(url) }}