iProgrammed
iProgrammed

Reputation: 980

How to only allow one Recipients in Mail in iOS

I am creating an Contact Us button which would allow the User to contact our Support Team by Email(I am using iOS 6). But I want the Mail Composer only email our support team email and not allow the user to add or delete recipients email address.

DemoProject.h

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h> 

@interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)

DemoProject.m

 - (IBAction)showEmail:(id)sender {
    // Email Subject
    NSString *emailTitle = @"Test Email";
    // Email Content
    NSString *messageBody = @"iOS programming is so fun!";
    // To address
    NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"];

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:NO];
    [mc setToRecipients:toRecipents];

    // Present mail view controller on screen
    [self presentViewController:mc animated:YES completion:NULL];

}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail sent failure: %@", [error localizedDescription]);
            break;
        default:
            break;
    }

    // Close the Mail Interface
    [self dismissViewControllerAnimated:YES completion:NULL];
} `

Upvotes: 0

Views: 754

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50129

you can't limit that. you can prefill the field, but you cant limit the user from editing the recipients.

Upvotes: 2

Related Questions