I've been looking around for a framework to simply allow me to send an email from inside my app. I have tried MailCore, Pantomime and SKPSMTP all with no luck. I can't get them to compile in Xcode, so I presumed they were outdated. Is there any way I can do this? If so, how? Thanks.
-
There is a way to pop up a new email box in your app with your content, but the user controls whether to send it. I'm not sure implementing your own SMTP inside an app will be approved by apple. – Daniel Aug 17 '11 at 02:01
-
Maybe not, but there are many apps out there which implement this aren't there? The context in which this is in, is a booking form for a hotel. So if I add a send button, and apple see i'm not doing anything nasty, I can't see any reason it would be rejected. Unless I missed something in the guidelines. Thanks for your input though. – Alex Aug 17 '11 at 02:10
-
I have compiled the SKPSMTP code successfully. Try adding the .m files explicitly to the Build Phases/Compile Sources. – Ellis Apr 02 '12 at 02:03
-
Possible duplicate Question at http://stackoverflow.com/a/12054952/846372 – Soniya Aug 21 '12 at 12:37
4 Answers
You can easily send emails from your iOS device. No need to implement SMTP and all. Best thing about using inbuilt emailing facilities in iOS is it gives you access to the address book! So it auto-completes names, email addresses. Yaaiiii!!
Include, AddressBook
,AddressBookUI
and MessageUI
frameworks and code something like this. Note you can even choose to send content as HTML too!
#import <MessageUI/MessageUI.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
MFMailComposeViewController *mailComposer;
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setSubject:@"your custom subject"];
[mailComposer setMessageBody:@"your custom body content" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
For the sake of completeness, I have to write this selector to dismiss the email window if the user presses cancel
or send
-
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
[self dismissModalViewControllerAnimated:YES];
return;
}
Happy coding...

- 71,928
- 54
- 216
- 264
-
Thanks for your detailed and somewhat humorous response! :) Will this bring the mail screen up from the bottom, or send it silently in the background? Because I'm aiming for the latter. – Alex Aug 17 '11 at 02:07
It should be noted that MFMailComposeViewController
has a method called canSendMail. If you don't check this before presenting a MFMailComposeViewController
on a device that doesn't have an email account, you'll get a SIGABRT.
It's easy to miss this when testing on the device or the simulator since you'll probably have an email account on your Mac and your iPad.
SKPSMTPMessage still works fine for sending emails without the need for a UI .
Make sure you add a reference to the CFNetwork.framework
in your project. Otherwise you will get build errors.

- 5,553
- 1
- 22
- 37
-
3I used this `SKPSMTPMessage`. But it needs to hardcode the user name and the password. But I want to send the email using already signed in email account in the iPhone. How can I do that – iDia Jan 22 '13 at 04:22
I would imagine the Apple Approved way of doing this would be to send the data to a server via HTTP Post, and have the server generate the mail for you. I've seen others asking similar questions to this, and the answer is that if you send it from the device, you really need to prompt the user.
I can even tell you why this is: Imagine an application that could send itself to everyone in your address book without the your confirmation, telling them that you just installed application X, and they should too. Even if well intentioned, this could quickly create a huge SMTP storm, and in essence this would be the "I love you" virus.
That was enough of a strain on the public internet, but on wireless carriers, could quickly cause enough overload to block cel service.
Conclusion: Either use the ComposeViewController as @Srikar suggests, or else POST the data to your server, and send it from there.

- 3,400
- 1
- 23
- 45
-
I understand that, but if I wasn't to use the apple built in frameworks, then I wouldn't need access to the address book. Just one from email, and one to email. But if this is not possible, I'll just have to get the user to fill in the form, and the email be generated for them just to press send. – Alex Aug 17 '11 at 11:03