Search code examples
iphonecocoa-touchmfmailcomposeviewcontroller

In-App Mail Account selection


is it possible to have the user select an account from which he wants to send the mail ?

I can send a mail but it's always from the default account and i want the user to be able to select which account he will use to send the email.


Solution

  • If the user taps on the From: address they can switch accounts, this behavior is identical to the normal email composer.

    This is the code I'm using to launch the mail composer:

    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    
    AssetsLibraryBroker *libraryBroker = [[AssetsLibraryBroker alloc] init];
    // loop through selected items;
    for (NSString *fileName in [self.selectedDictionary allKeys]) {
        NSLog(@"fileName: %@", fileName);
        [controller addAttachmentData:[libraryBroker getAssetDataForFileName:fileName inManagedObjectContext:managedObjectContext]  mimeType:@"image/jpeg" fileName:[NSString stringWithFormat:@"%@.jpg", fileName]];
    }
    
    [libraryBroker release];
    
    [self presentModalViewController:controller animated:YES];
    [controller release];
    

    My mail composer has a tap-able "From:" field.

    Launched from Code select an account