I want to send an email from my iPhone application. I have heard that the iOS SDK doesn't have an email API. I don't want to use the following code because it will exit my application:
NSString *url = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
So how can I send an email from my app?
A few things I'd like to add here:
Using the mailto URL won't work in the simulator as mail.app isn't installed on the simulator. It does work on device though.
There is a limit to the length of the mailto URL. If the URL is larger than 4096 characters, mail.app won't launch.
There is a new class in OS 3.0 that lets you send an e-mail without leaving your app. See the class MFMailComposeViewController.
This is the code which can help u but dont forget to include message ui framewark and include delegates method MFMailComposeViewControllerDelegate
Below code is used in my application to send email with an attachment here the attachments is an image .You can send any type of file only thing is to keep in mind is that you had to specify the correct 'mimeType'
add this to your .h file
Add MessageUI.framework to your project file
Delegate method is as shown below
To send an email from iPhone application you need to do below list of task.
Step 1: Import
#import <MessageUI/MessageUI.h>
In your controller class where you want to send an email.Step 2: Add the delegate to your controller like shown below
Step 3: Add below method for send email.
Step 4: Implement MFMailComposeViewController Delegate
Swift 2.2. Adapted from Esq's answer
Client code :
Swift 2.0