1

I'd like to setup a button in the iPhone app I'm making to send an email with the results of some operations performed earlier in the app. I've read other people comment on here that you can use other frameworks but, frankly, I can't find one that actually works. I've heard MailCore is good. Has anyone been able to send an email seamlessly through an iPhone app?

Note: I do not want to exit the app to send the email.

Darkenor
  • 4,349
  • 8
  • 40
  • 67
  • 6
    Do you want the user to be aware of this email being sent, or do you just want to send it in the background? It is always a possibility to use the MessageUI framework built-in to the SDK to display a send email dialogue. If you want to send an email in the background, I might suggest having a backend send the email after an HTTP request is made. – Alex Nichol Aug 07 '11 at 20:00
  • Definitely don't want them to see the request. I was thinking about using a backend, but the only ones I could find that were decent were quite difficult to get to just compile. I think Dtuckernet's suggestion might work. – Darkenor Aug 08 '11 at 21:23

3 Answers3

1

Answer From this Question: How can I send mail from an iPhone application

On iPhone OS 3.0 and later you should use the MFMailComposeViewController class, and the MFMailComposeViewControllerDelegate protocol, that that tucked away in the MessageUI framework. Note you must link the Message UI Framework and import its headers.

#import <MessageUI/MFMailComposeViewController.h>

First 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];
}
Community
  • 1
  • 1
rich
  • 2,136
  • 19
  • 23
  • This involves leaving the application. It's why the other question was ignored. – Darkenor Aug 08 '11 at 17:00
  • Can you explain how using a modal view constitutes leaving an application? When the view is dismissed you will return to your application. – rich Aug 08 '11 at 18:55
0
MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];  
mailComposer.mailComposeDelegate = self; 
NSString *emailBody = @"Write email body text here........";
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
user2998756
  • 71
  • 3
  • 5
0

In this case, your best bet is to use a service like Amazon Simple Email Service (SES). It will enable you to send the email without ever leaving the application (unlike the other solutions listed). Amazon AWS has an iOS SDK which can utilize the SES service. This service is super simple to use, and the cost is extremely low.

http://aws.amazon.com/sdkforios/

dtuckernet
  • 7,817
  • 5
  • 39
  • 54
  • Now *THAT* looks like a great Idea. I'm going to look into it ASAP. If I like it I'll mark your answer up. Very inventive. Getting MailCore to compile was getting pretty tough. – Darkenor Aug 08 '11 at 17:00