tags:

views:

130

answers:

1

hi, i am using MailComposerViewController from apple site.but when i send my message with empty cc,bcc field it gives error. it asks to fill that field .how can i send without cc, bcc with empty field . bcos it is optional to users....any help??????

A: 

I'm not sure what it is you're missing, but here you have something that might help you:

-Make sure that you're implementing the MFMailComposeViewControllerDelegate Delegate protocol.

-Here you have a snippet of code that works for me:

MFMailComposeViewController * mc = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
mc.mailComposeDelegate = self;  
[mc setToRecipients:[NSArray arrayWithObject:self.selectedRecipientEmail]];
NSString * subject = [NSString stringWithFormat:NSLocalizedString(@"Mail subject", nil)];    
[mc setSubject: subject];
[mc setMessageBody: [self composeMessageBodyAsHTML] isHTML:YES];
[self presentModalViewController:mc animated:YES];
[mc release];

And here you have the delegate method

#pragma mark MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

switch (result)
{
    case MFMailComposeResultCancelled:
     // Do something
     break;
    case MFMailComposeResultSaved:
     message = NSLocalizedString(@"Saved! The email was successfully saved", @"Email saved message");
     // Do something
     break;
    case MFMailComposeResultSent:
     // Do something
     break;
    case MFMailComposeResultFailed:
     // Do something
     break;
    default:
     // Do something
     break;
}
}

I hope this helps, good luck!

Lio