iOS send email
Send Email for IOS
Introduction
We can send email using email application in IOS device.
Instance steps
1. Create a simple View based application
2. Select the project file, then select the target, and then add MessageUI.framework
3. Add a button to ViewController.xib and create an action for sending emails
4. Update ViewController.h as shown below
#import <UIKit/UIKit.h>#import <MessageUI/MessageUI.h>@interface ViewController : UIViewController<MFMailComposeViewControllerDelegate>{ MFMailComposeViewController *mailComposer;}-(IBAction)sendMail:(id)sender;@end
5. As shown below , update ViewController.m
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}-(void)sendMail:(id)sender{ mailComposer = [[MFMailComposeViewController alloc]init]; mailComposer.mailComposeDelegate = self; [mailComposer setSubject:@"Test mail"]; [mailComposer setMessageBody:@"Testing message for the test mail" isHTML:NO]; [self presentModalViewController:mailComposer animated:YES];}#pragma mark - mail compose delegate-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ if (result) { NSLog(@"Result : %d",result); } if (error) { NSLog(@"Error : %@",error); } [self dismissModalViewControllerAnimated:YES];}@end
Output
When running the application, you will see the following output
When you click "send email" button, you can see the following results: