开发者

Sending email through iPhone application

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 c开发者_运维技巧omment 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.


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];
}


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/


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜