Search code examples
iosiphoneios5mfmailcomposeviewcontrollermfmailcomposer

MFMailComposeViewController not populating recipients in ios 5


I'm trying to send mail to list of email array that I receive from database, when I send the recipient list gets populated in iOS 7 but when I tried in iOS 5 the recipient list doesn't get populated. Any Idea why? This is my mail function

-(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
{
    if([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
        mailComposer.view.tag=tag;
        NSString *htmlBody =[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",_currentAdd.contentUrl,addtext];
        [mailComposer setMessageBody:htmlBody isHTML:YES];
        [mailComposer setSubject:_currentMail.subject];
        mailComposer.mailComposeDelegate = self;
        [mailComposer setToRecipients:fList];
        [self presentViewController:mailComposer animated:YES completion:nil];
    }
    else
    {
       NSLog(@"Device is unable to send email in its current state.");
    }
}

My fList (recipient list) is an NSArray, this is a sample output of my fList

(
    "[email protected]",
    "[email protected]",
    "[email protected]",
    "[email protected]"
)

Solution

  • -(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
    {
        if([MFMailComposeViewController canSendMail])
        {
            MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
            //mailComposer.view.tag=tag;
            NSString *htmlBody =[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",_currentAdd.contentUrl,addtext];
            [mailComposer setMessageBody:htmlBody isHTML:YES];
            [mailComposer setSubject:_currentMail.subject];
            mailComposer.mailComposeDelegate = self;
            [mailComposer setToRecipients:fList];
            [self presentViewController:mailComposer animated:YES completion:nil];
        }
        else
        {
           NSLog(@"Device is unable to send email in its current state.");
        }
    }
    

    Apparently the issue was with setting tag if I try to set the tag before setToRecipients line it will not show the recipients list in iOS 5, it will work if the setting tag line is commented out or set after setToRecipients.