iPhone Tutorial - In app Email

Ok, so here is a tutorial for getting the Mail.app modal view in your application for OS 3.0+ and to launch Mail.app from your application if your on 2.X.X.

99% of the time, this is going to be run as an event, or a response to user input (pressing a UIButton, responding to a UIAlertView, etc.), so right off the bat, you know its going to be a -(IBAction) (if, of course, your using the Interface builder).
First, however, we are going to want to import the mail framework, titled "MessageUI.framework". So right click on the "Frameworks" folder, then click "Add" then "Existing Frameworks" then "MessageUI.framework". Now you should see this:

This will allow you to access those oh-so-special frameworks you just added. We now just have to add the methods to call the Mail.app modal view. So add these to your .h file under your @property calls.
[OBJC]
- (void)displayComposerSheet;
- (void)showPicker;
- (void)launchMailAppOnDevice;
- (IBAction)callMail;[/OBJC]

This is the call for the methods that we are going to define in your .m file. Speaking of which, turn to your .m file now, and I will break down what is necessary to call to make this puppy work.
First, we need an -(IBAction) to call our method. This is what callMail { } is for. So make a UIButton and assign callMail { } to it. If don't know how to do this, then the easiest way in in the Interface Builder. In the IB, click on "File's Owner" and then on the "Connections" tab in the inspector. You should see "Received Actions" and under that, "callMail". Click on the "+" sign next to callMail, and drag it to your UIButton. It will give you a drop-down menu. Choose "Touch Up Inside." As shown:

This is the method we just called. This method checks if the device can bring up the modal view. If it can, it calls the method to do so. If it can't, it tells the divice to open Mail.app. Now we need to call the modal view itself:

The above will call the mail composition GUI as a modal view inside your application. From here, you can set the subject, recipients, cc's, bcc's and the body text. (This, of course, ends up being totally editable by the end user, however).

Remove your images of code and replace them with actual code. Wrap the code in [OBJC] tags. It will make thigns much easier for those with older monitors, or whose broswers resize the images so they are far too compressed to read. It also helps if people who look at the tutorial can actually have the code to copy into their apps so they can see it in action.

Remove your images of code and replace them with actual code. Wrap the code in [OBJC] tags. It will make thigns much easier for those with older monitors, or whose broswers resize the images so they are far too compressed to read. It also helps if people who look at the tutorial can actually have the code to copy into their apps so they can see it in action.