Xcode 4 / iOS - Send an email using SMTP from inside my app
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...
How to send mail from iphone app without showing MFMailComposeViewController?
Sending emails programmatically, without user intervention, from an iphone application, cannot be implemented using any of the Apple frameworks. It could be possible in a jailbroken phone but then it would never see the inside of App Store.
If you want control of email sending, then a better way would be to set up a web service (at your server end) you can post to using an HTTP request. If you are posting to only one address this can work very well, although you may want to get the user to input their return mail address.
Otherwise only the standard dialog is available (this relies on using whatever account they've setup on the device).
Send email with content without using webservice in iPhone app
I have achieved this with SMKSMTPMessage - a library that allows you to send an email with attachments if required from code, without any user interaction required
Related Topics
Xcode 5.1: Missing Required Architecture Arm64
Uitableviewcell Checkmark to Be Toggled on and Off When Tapped
Find the Tangent of a Point on a Cubic Bezier Curve
Distancefromlocation - Calculate Distance Between Two Points
Localizing Strings in iOS: Default (Fallback) Language
How to Add an Action to a Button Programmatically in Xcode
iOS 11 - Keyboard Height Is Returning 0 in Keyboard Notification
Uitableviewcell Buttons with Action
Refresh Devices in Team Provisioning Profile Managed by Xcode 7
Swift - How to Hide Back Button in Navigation Item
How Does Cellforrowatindexpath Work
Enterprise In-House App Distribution
Swift Performselector:Withobject:Afterdelay: Is Unavailable
When How to Activate/Deactivate Layout Constraints
Why Push Notifications Is Not Working on Testflight
How to Change the Tint Color of the Clear Button on a Uitextfield