Reputation: 230
I found email composer sample code from iphone OS Ref Library. Here is a code-
Code:
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
My question is how to take user's input? Here all email address are predefined in code. so what are the IDs of to, CC, Bcc, subject and body fields?
Upvotes: 0
Views: 1330
Reputation: 9390
Use this code. To Give a Email address as user input only.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *msgTitle = @"Sample Title";
[picker setSubject:msgTitle];
NSArray *toRecipients =[[NSArray alloc] init];
NSArray *ccRecipients =[[NSArray alloc] init];
NSArray *bccRecipients =[[NSArray alloc] init];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
NSString *sum = @"The Email Body string is here";
NSString *emailBody;
emailBody = [NSString stringWithFormat:@"%@",sum];
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:?cc=,&subject=@";
NSString *body = @"&body=";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
Best of luck.
Upvotes: 1
Reputation: 13833
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:arr];
[controller setCcRecipients:arr2];
[controller setBccRecipients:arr3];
[controller setMessageBody:@"Hello there." isHTML:NO];
Upvotes: 1