views:

20

answers:

3

Hi,

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 protected]&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

A: 

stringWithFormat: should work.

what type of variables are EMAIL and SUBJECT? Also, can you post the code you used for stringWithFormat:?

jmont
EMAIL and SUBJECT resemble NSStrings.
Alex
A: 

Try

-(IBAction)sendEmail:(id)sender { 
NSURL* mailURL = [NSURL URLWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!"]; [[UIApplication sharedApplication] openURL: mailURL]; 
} 
Biranchi
A: 
NSString *emailInfo = [NSString stringWithString: @"mailto:[email protected]&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 protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [emailInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
Biranchi