programmatically create Email option in iPhone

 #import <MessageUI/MFMailComposeViewController.h>  
On iOS 3.0 and later you should use the MFMailComposeViewController class, and the MFMailComposeViewControllerDelegate protocol, that that tucked away in the MessageUI framework.
First add the framework and import:
 #import <MessageUI/MFMailComposeViewController.h>  
 

Then, to send a message:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];  
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO]; if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
 

Then the user does the work and you get the delegate callback in time:

 - (void)mailComposeController:(MFMailComposeViewController*)controller   
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
 

Remember to check if the device is configured for sending email:

 
if ([MFMailComposeViewController canSendMail]) {  
// Show the composer
} else {
// Handle the error
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>