jinal
jinal

Reputation: 69

can't set Mailto field in MFMailComposeViewController in iphone

I have write code to send mail on button click.But i have email id programatically. I have output like this.

[email protected] Send MailButton

Now when i click on Send MailButton then it open MFMailComposeViewController but to field is empty.Here [email protected] is change dynamically it's not fixed.

My code is

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail])
{
    NSString *emailBody;
    emailBody=self.shareString;
    //NSLog(@"EMail Body ---- %@",emailBody);

    [picker setMessageBody:emailBody isHTML:YES];
    [picker becomeFirstResponder];

    [self presentModalViewController:picker animated:YES];
}

What should be change here required?

Upvotes: 1

Views: 431

Answers (2)

IronManGill
IronManGill

Reputation: 7226

Well you need to create an array for this first.

-(void)displayComposerSheetEmailUs{

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Hello from the App!"];

    // Set up recipients
             NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
             [picker setToRecipients:toRecipients];

    // Fill out the email body text
        NSString *emailBody = @"It is raining in sunny California!";
        [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];

}

Upvotes: 0

Hemang
Hemang

Reputation: 1234

Use following code:

NSArray *tempArray = [[NSArray alloc] initWithObjects:@"[email protected]", nil];
[picker setToRecipients:tempArray];

It's working properly for me.

Thanks, Hemang.

Upvotes: 1

Related Questions