IOS - How to send an E-mail informing the recipient?

0

I'm trying to send an e-mail with the recipient already informed, but I do not know how to pass this information in the code.

Code:

-(IBAction) mail : (id) sender{
    mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;
    [mailComposer setSubject:@"test mail"];
    [mailcomposer setMessageBody:@"Msg teste do Mail"
                          isHTML:NO];
    [self presentModalViewController:mailComposer animated:YES];
}

I also used MessageUI.framework

    
asked by anonymous 15.02.2016 / 19:42

1 answer

1

You can use the setToRecipients method of MFMailComposeViewController. Remember that as you can send to more than one recipient, so the method will wait for an input array.

NOTE: The method needs to be called before displaying the view on the screen. After the view is displayed, this method will no longer be available.

Examples:

Passing a fixed email:

[picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]];

Passing an email which may vary:

NSArray *arrayQueVemDeAlgumLugar = @["[email protected]"];
[picker setToRecipients:arrayQueVemDeAlgumLugar;

More than one email:

[picker setToRecipients:@[@"[email protected]", @"[email protected]", nil]];

Remembering that the pattern with which you create / pass the array via parameter can change as you find it readable.

If you want to see more information about how MFMailComposer works

    
15.02.2016 / 20:21