Reputation: 8036
I just tried to send email using this code and it seems to work:
NSString* urlEmail = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=test%20from%20me!&body=this%20is%20a%20test!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]];
The only problem is, is there a function I can use to automatically escape everything in a normal NSString so I don't have to write it out manually like this? If not, how can I use stringWithFormat without conflicting with the % signs already in the string? I basically want to be able to append to, subject, body, etc. dynamically.
Upvotes: 1
Views: 4284
Reputation: 430
Use MFMailComposeViewController:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setToRecipients:recipients];
[picker setSubject:subject];
[picker setMessageBody:body isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
Upvotes: 9
Reputation: 2818
According to https://stackoverflow.com/a/917630/535632, you can escape like this:
NSString *urlStr = [urlEmail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Upvotes: 1