Mail Composer in iPad


In this article I will create a Single View application with a button from Xib. When we click on the button, the message composer opens.

To understand it we use the following.

Step 1

Open XCode by double-clicking on it.

Step 2

Create a new XCode Project by clicking on it.

Step 3

Now select Single View Application and click on Next.

Step 4

Now provide your Product Name and Company Identifier.

Step 5

Select the location where you want to save your project and click on Create.

Step 6

Now we write the code.


#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController < MFMailComposeViewControllerDelegate>
IBOutlet UIButton *button;
- (IBAction)buttonPressed;


#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
if ([MFMailComposeViewController canSendMail])
button.enabled = YES;
- (IBAction)buttonPressed {

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];

mailController.mailComposeDelegate = self;

[mailController setSubject:@"Hello Sachin"];

[mailController setMessageBody:@"This is the Email Application" isHTML:NO];

[self presentModalViewController:mailController animated:YES];

[mailController release];

- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

[self becomeFirstResponder];

[self dismissModalViewControllerAnimated:YES];

- (void)dealloc {

[button release];

[super dealloc];


Step 7

Finally we click on the Run button to show the output.

Step 8

Output1 in iPad:


Output2 in iPad:


Output3 in iPad:


Similar Articles