E-mail App in iPhone


In this article I will create a single View application. Here we use two text fields, one text view, two label and one button through Xib. In this app we make a customized mailing app for iPhone.

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 for the code.


#import <UIKit/UIKit.h>
@interface testviewViewController : UIViewController
IBOutlet UITextField *to;
IBOutlet UITextField *subject;
IBOutlet UITextView *body;
@property (nonatomic, retain) UITextField *to;
@property (nonatomic, retain) UITextField *subject;
@property (nonatomic, retain) UITextView *body;
-(IBAction) btnSend: (id) sender;


#import "testviewViewController.h"
@interface testviewViewController ()
@implementation testviewViewController
@synthesize to, subject, body;

- (void) sendEmailTo:(NSString *) toStr withSubject:(NSString *) subjectStr
withBody:(NSString *) bodyStr {
NSString *emailString =
[[NSString alloc] initWithFormat:@"mailto:?to=%@&subject=%@&body=%@",
[toStr stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding], [subjectStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], [bodyStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailString]];
[emailString release];
-(IBAction) btnSend: (id) sender{
[self sendEmailTo:to.text withSubject:subject.text withBody:body.text];
- (void)dealloc { [to release];
[subject release]; [body release]; [super dealloc];



Step 7

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


Output 1 in iPhone:


Output 2 in iPhone: