Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setToRecipients with MFMailComposeViewController

I'm trying to get emails that i select to send an email. But i dont know how to setToRecipients which users that i heve selected in the MFMailComposeViewController view.

if ([MFMailComposeViewController canSendMail])
    {
        mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"A Message from blablabl"];

        NSMutableArray *usersTo = [[NSMutableArray alloc] init];
        toRecipients = usersTo;
        [mailer setToRecipients:toRecipients];

        NSString *emailBody = @"blablablabal";

        [mailer setMessageBody:emailBody isHTML:YES];

        // only for iPad
        // mailer.modalPresentationStyle = UIModalPresentationPageSheet;

        [self presentModalViewController:mailer animated:YES];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                                                        message:@"Your device doesn't support the composer sheet" 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles: nil];
        [alert show];
    }

Delegate http://pastie.org/3281814

like image 587
user1177647 Avatar asked Jan 30 '12 12:01

user1177647


2 Answers

A couple things are wrong here.

1 )

MFMailComposeViewController's setToRecipients method expects an immutable array with recipients already set.

2 )

And you're setting it to a blank mutable array.

Try something like this:

NSArray *usersTo = [NSArray arrayWithObject: @"[email protected]"];
[mailer setToRecipients:usersTo];

And you should see it work.

like image 55
Michael Dautermann Avatar answered Sep 18 '22 09:09

Michael Dautermann


   MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
   NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]",@"[email protected]",nil];   
   [picker setToRecipients:toRecipients];
like image 29
Tendulkar Avatar answered Sep 21 '22 09:09

Tendulkar