0

I'd like to make it so the user can send an email address which comes from a predefined email address. So the user does not specify the email address.

However, I'd like it so they do define the recipient's email and the content of the email address.

This is what I tried using earlier, which goes through the Mail client:

NSString *emailInfo = [NSString stringWithString: @"mailto:EMAIL?cc=bar@foo.com&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]];

The thing is, I want to make it so MAIL & SUBJECT resemble the toEmail and content variables which are used in UITextFields.

I tried using stringWithFormat but it didn't work.

Any ideas?

Thanks

Alex
  • 81
  • 2
  • 11

2 Answers2

0

Try

-(IBAction)sendEmail:(id)sender { 
NSURL* mailURL = [NSURL URLWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!"]; [[UIApplication sharedApplication] openURL: mailURL]; 
} 
Biranchi
  • 16,120
  • 23
  • 124
  • 161
0
NSString *emailInfo = [NSString initWithString: @"mailto:EMAIL?cc=bar@foo.com&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]]

Probable cause of error is NSURL object: I guess [NSURL URLWithString: emailInfo] is returning null.

Try printing to console

 NSLog(@"URL = %@", [NSURL URLWithString: emailInfo]);

So I would suggest you to go for string encoding.

NSString *emailInfo = [NSString stringWithString: @"mailto:EMAIL?cc=bar@foo.com&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [emailInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
dda
  • 6,030
  • 2
  • 25
  • 34
Biranchi
  • 16,120
  • 23
  • 124
  • 161