Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set from in MFMailComposeViewController?

How do I set the from address in the MFMailComposeViewController?

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"In app email..."];
[controller setMessageBody:@"To FirstName LastName: " isHTML:NO];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; // (NSString *) [feed valueForKey:@"email"]]; 
[controller setToRecipients:toRecipients];
like image 780
HardCode Avatar asked Nov 02 '11 15:11

HardCode


2 Answers

There isn't a way to do what you want with the From field. The from address will default to whatever mail account the user has specified as "default" in Settings. Obviously if the user has only one mail account set up then it will be that account.

like image 119
Brian Driscoll Avatar answered Oct 21 '22 16:10

Brian Driscoll


This is possible since iOS 11.0

Use setPreferredSendingEmailAddress(_:) to define a preferred address which will automatically select a corresponding account if available.

From the documentation:

Sets the preferred email address to use in the From field, if such an address is available.

If the user does not have an account with a preferred address set up, the default account is used instead. Call this method before you display the mail composition interface only. Do not call it after presenting the interface to the user.

like image 34
heyfrank Avatar answered Oct 21 '22 16:10

heyfrank