使用mailto:URL发送电子邮件 [英] Sending Email using mailto: URLs
本文介绍了使用mailto:URL发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我下面的代码?对于在iOS中发送电子邮件,下面的代码是一个好的,或者应该使用MFMailComposeViewController比这??
Can someone help me with the following code? For sending email in iOS, is the below code a good one or should I use the MFMailComposeViewController than this?:
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]];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]];
是否是发送邮件的可靠代码?
Is it a reliable code for sending mail?
推荐答案
如果这是针对IOS 3.0+,则MFMailCompseViewController
If this is targeted for IOS 3.0+ then MFMailCompseViewController
#import <MessageUI/MFMailComposeViewController.h>
// ....
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(@"sent");
}
[self dismissModalViewControllerAnimated:YES];
}
这篇关于使用mailto:URL发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文