views:

185

answers:

3

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?

+1  A: 
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setToRecipients:arr];
    [controller setCcRecipients:arr2];
    [controller setBccRecipients:arr3];
    [controller setMessageBody:@"Hello there." isHTML:NO]; 
mihirpmehta
A: 

Hi Arun Sharma,

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.

Pugal Devan
Thanks for your answer.I implement that code and its work successfully.........
Arun Sharma
-(void)launchMailAppOnDeviceis it required to modifyif yes then please tell me how i put all arrays in this method
Arun Sharma
@Arun Sharma. I think thats method is not reqired. If u want more details, see my updated answer. It may help you. Thanks.
Pugal Devan
A: 

Thanks a lot! Big help!!!! XD

giselleanxa