MailSend in the iPhone

In this application we will see how to send mail from the iPhone. User just simple click in the ToRecipient , and it will take address from the addressbook. So let see how it will be worked.

In this application we will see how to send mail from the iPhone. User just simple click in the ToRecipient , and it will take address from the addressbook. So let see how it will be worked.

Step 1: Create a View base application using template. Give the application name “MailSend”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the MailSendViewController class for you. Expand Resources and notice the template generated a separate nib, MailSendViewController.xib, for the “MailSend”.

Step 4: We need to add MessageUI Framework. After hitting the Add -> Existing Framework .. menu item an open panel will popup. Navigate to this directory.

Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks

Step 5: In the MailSendViewController.h file,we have to import MessageUI.h file and added UIButton for create a button and a method.  S make the following changes in the file.

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

@interface MailSendViewController : UIViewController
<MFMailComposeViewControllerDelegate> {
       
        IBOutlet UIButton *myButton;
}

- (IBAction)buttonPressed;

Step 6: Double click the MailSendViewController.xib file and open it to the Interface Builder. Open the view icon and drag the Round Rect from the library and place it to the view window. Double click the button and give the name “PressButton”. Now connect  File’s Owner icon to the View icon and select view. Drag File’s Owner icon to the PressButton and select myButton. Select “PressButton” and bring up connection inspector and drag to the TouchUpInside to the File’s Owner icon and select buttonPressed: action. Now save it, close it and go back to the Xcode.

Step 7: Open the MailSendViewController.m file and make the following changes:

- (void)viewDidLoad {
  if ([MFMailComposeViewController canSendMail])
  myButton.enabled = YES;
}

- (IBAction)buttonPressed {
  MFMailComposeViewController *mailController= [[MFMailComposeViewController alloc] init];
  mailController.mailComposeDelegate = self;
  [mailController setSubject:@"Hello iPhone"];
  [mailController setMessageBody:@"This is the MailSend Application…." isHTML:NO];
  [self presentModalViewController:mailController animated:YES];
  [mailController release];
}

-   (void)mailComposeController:(MFMailComposeViewController*)mailCon troller didFinishWithResult:(MFMailComposeResult)result  error:(NSError*)error {
  [self becomeFirstResponder];
  [self dismissModalViewControllerAnimated:YES];
}

  - (void)dealloc {
  [myButton release];
  [super dealloc];
}

Step 8: Now compile and run the application in the Simulator.

You can downloaded SourceCode from here MailSend 2

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

1 Response » to “MailSend in the iPhone”

  1. kimziv says:

    Thank you ! your article is very helpful for me

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG