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

Asked

Viewed 38 times

0

I am 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

1 answer

1


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

NOTE: The method needs to be called before 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 that may vary:

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

More than one email:

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

Remember, that the pattern with which you create/pass the array via parameter can change as you find more readable.

If you want more information about how Mfmailcomposer works

Browser other questions tagged

You are not signed in. Login or sign up in order to post.