iOS发邮件功能
2016-02-29 09:54
501 查看
步骤
1.先导入MessageUI.framework系统库
2.#import <MessageUI/MFMailComposeViewController.h>
3.签代理MFMailComposeViewControllerDelegate
4.代码
5.在真机测试时控制台会打印出 您的设备尚未配置邮件账号
解决办法
1)打开邮箱(以qq邮箱为例) 设置----账户----POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务---
POP3/SMTP服务 (如何使用 Foxmail 等软件收发邮件?)
已开启 |
关闭
IMAP/SMTP服务 (什么是 IMAP,它又是如何设置?)
已开启 |
关闭
CardDAV/CalDAV服务 (什么是CardDAV/CalDAV,它又是如何设置?)
已开启 |
关闭
开启这三个,开启时发送完短信之后获得密码
2)在真机中 打开 设置----邮件.通讯录.日历----添加账户---其他----添加邮件账户(填写信息完成后,填写你要发送到的邮箱)---保存
1.先导入MessageUI.framework系统库
2.#import <MessageUI/MFMailComposeViewController.h>
3.签代理MFMailComposeViewControllerDelegate
4.代码
- (void)businessContactWithMail { Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if (mailClass != nil) { //判断能否发送邮件 if ([mailClass canSendMail]) { //创建邮件控制器,准备发送邮件 MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; //设置主题 [controller setSubject:@"主题"]; //主收件人 [controller setToRecipients:@[@"<span style="font-family: SimSun;">邮箱网址</span>"]]; //抄送 [controller setCcRecipients:@[@"<span style="font-family: SimSun;">邮箱网址</span>"]]; //秘密抄送 [controller setBccRecipients:@[@"<span style="font-family: SimSun;">邮箱网址</span>"]]; //正文 [controller setMessageBody:@"正文" isHTML:NO]; //设置代理 [controller setMailComposeDelegate:self]; //显示控制器 [self presentViewController:controller animated:YES completion:^{ }]; [controller release]; } else { NSLog(@"您的设备尚未配置邮件账号"); } } else { NSLog(@"您的设备不支持邮件功能"); } }
//发完邮件调用代理方法关闭窗口 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { /** MFMailComposeResultCancelled, 取消 MFMailComposeResultSaved, 保存邮件 MFMailComposeResultSent, 已经发送 MFMailComposeResultFailed 发送失败 */ switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail send canceled..."); break; case MFMailComposeResultSaved: NSLog(@"Mail saved..."); break; case MFMailComposeResultSent: NSLog(@"Mail sent..."); break; case MFMailComposeResultFailed: NSLog(@"Mail send errored: %@...", [error localizedDescription]); break; default: break; } [self dismissViewControllerAnimated:YES completion:nil]; }
5.在真机测试时控制台会打印出 您的设备尚未配置邮件账号
解决办法
1)打开邮箱(以qq邮箱为例) 设置----账户----POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务---
POP3/SMTP服务 (如何使用 Foxmail 等软件收发邮件?)
已开启 |
关闭
IMAP/SMTP服务 (什么是 IMAP,它又是如何设置?)
已开启 |
关闭
CardDAV/CalDAV服务 (什么是CardDAV/CalDAV,它又是如何设置?)
已开启 |
关闭
开启这三个,开启时发送完短信之后获得密码
2)在真机中 打开 设置----邮件.通讯录.日历----添加账户---其他----添加邮件账户(填写信息完成后,填写你要发送到的邮箱)---保存
相关文章推荐
- iOS 优化界面流畅度的探讨
- iOS/OS X 内存管理(二):借助工具解决内存问题
- iOS/OS X内存管理(一):基本概念与原理
- iOS滑动tableView来改变导航栏的颜色
- iOS 获取照相机实时预览图片
- iOS自定义转场动画实战讲解
- iOS 开发之动画篇 - Transform和KeyFrame动画
- iOS-私有API与runtime
- iOS开发——iOS状态栏和导航栏的控制问题
- IOS设计模式之组合设计模式
- iOS开发:WebKit、Safari以及SafariViewController
- Nagios+NRPE安装备忘录(一)
- iOS检查继承关系
- 总结iOS App开发中控制屏幕旋转的几种方式
- iOS崩溃调试
- 整理常用的iOS第三方资源
- iOS 关闭键盘 [self endEditing: YES]
- 让web应用正常显示ios输入法表情
- 如何让自己的web应用支持iOS表情
- [ios]iOS 图形编程总结