//方法1
//用自带的邮件客户端,发完邮件后不会自动回到原应用
NSURL *url = [NSURL URLWithString:@"mailto://10010@qq.com"];
[[UIApplication sharedApplication] openURL:url];
//方法2
//跟发短信的第2种方法差不多,只不过控制器类名叫做:MFMailComposeViewController
邮件发送后的代理方法回调,发完后会自动回到原应用
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
// 关闭邮件界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MFMailComposeResultCancelled) {
NSLog(@"取消发送");
} else if (result == MFMailComposeResultSent) {
NSLog(@"已经发出");
} else {
NSLog(@"发送失败");
}
}
iOS 常用小功能——发邮件
最新推荐文章于 2025-03-13 00:28:03 发布
本文详细对比了使用自带邮件客户端发送邮件与通过原应用接口调用发送邮件的方法,提供了两种实现方式的代码示例,并讨论了它们在用户交互体验上的不同。适合对iOS开发邮件功能感兴趣的开发者参考。
1248

被折叠的 条评论
为什么被折叠?



