iOS - 发送邮件
1.openURL
- #pragma mark - 使用系统邮件客户端发送邮件
- -(void)launchMailApp
- {
- NSMutableString *mailUrl = [[[NSMutableString alloc]init]autorelease];
- //添加收件人
- NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com"];
- [mailUrl appendFormat:@"mailto:%@", [toRecipients componentsJoinedByString:@","]];
- //添加抄送
- NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
- [mailUrl appendFormat:@"?cc=%@", [ccRecipients componentsJoinedByString:@","]];
- //添加密送
- NSArray *bccRecipients = [NSArray arrayWithObjects:@"fourth@example.com", nil];
- [mailUrl appendFormat:@"&bcc=%@", [bccRecipients componentsJoinedByString:@","]];
- //添加主题
- [mailUrl appendString:@"&subject=my email"];
- //添加邮件内容
- [mailUrl appendString:@"&body=<b>email</b> body!"];
- NSString* email = [mailUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- [[UIApplication sharedApplication] openURL: [NSURL URLWithString:email]];
- }
2.MFMailComposeViewController
- 1.项目中引入MessageUI.framework;
- 2.在使用的文件中导入MFMailComposeViewController.h头文件;
- 3.实现MFMailComposeViewControllerDelegate,处理邮件发送事件;
- 4.调出邮件发送窗口前先使用MFMailComposeViewController里的“+ (BOOL)canSendMail”方法检查用户是否设置了邮件账户;
- 5.初始化MFMailComposeViewController,构造邮件体
- //
- // ViewController.h
- // MailDemo
- //
- // Created by LUOYL on 12-4-4.
- // Copyright (c) 2012年 http://luoyl.info. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- #import <MessageUI/MFMailComposeViewController.h>
- @interface ViewController : UIViewController<MFMailComposeViewControllerDelegate>
- @end
- #pragma mark - 在应用内发送邮件
- //激活邮件功能
- - (void)sendMailInApp
- {
- Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
- if (!mailClass) {
- [self alertWithMessage:@"当前系统版本不支持应用内发送邮件功能,您可以使用mailto方法代替"];
- return;
- }
- if (![mailClass canSendMail]) {
- [self alertWithMessage:@"用户没有设置邮件账户"];
- return;
- }
- [self displayMailPicker];
- }
- //调出邮件发送窗口
- - (void)displayMailPicker
- {
- MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
- mailPicker.mailComposeDelegate = self;
- //设置主题
- [mailPicker setSubject: @"eMail主题"];
- //添加收件人
- NSArray *toRecipients = [NSArray arrayWithObject: @"first@example.com"];
- [mailPicker setToRecipients: toRecipients];
- //添加抄送
- NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
- [mailPicker setCcRecipients:ccRecipients];
- //添加密送
- NSArray *bccRecipients = [NSArray arrayWithObjects:@"fourth@example.com", nil];
- [mailPicker setBccRecipients:bccRecipients];
- // 添加一张图片
- UIImage *addPic = [UIImage imageNamed: @"Icon@2x.png"];
- NSData *imageData = UIImagePNGRepresentation(addPic); // png
- //关于mimeType:http://www.iana.org/assignments/media-types/index.html
- [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"];
- //添加一个pdf附件
- NSString *file = [self fullBundlePathFromRelativePath:@"高质量C++编程指南.pdf"];
- NSData *pdf = [NSData dataWithContentsOfFile:file];
- [mailPicker addAttachmentData: pdf mimeType: @"" fileName: @"高质量C++编程指南.pdf"];
- NSString *emailBody = @"<font color='red'>eMail</font> 正文";
- [mailPicker setMessageBody:emailBody isHTML:YES];
- [self presentModalViewController: mailPicker animated:YES];
- [mailPicker release];
- }
- #pragma mark - 实现 MFMailComposeViewControllerDelegate
- - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
- {
- //关闭邮件发送窗口
- [self dismissModalViewControllerAnimated:YES];
- NSString *msg;
- switch (result) {
- case MFMailComposeResultCancelled:
- msg = @"用户取消编辑邮件";
- break;
- case MFMailComposeResultSaved:
- msg = @"用户成功保存邮件";
- break;
- case MFMailComposeResultSent:
- msg = @"用户点击发送,将邮件放到队列中,还没发送";
- break;
- case MFMailComposeResultFailed:
- msg = @"用户试图保存或者发送邮件失败";
- break;
- default:
- msg = @"";
- break;
- }
- [self alertWithMessage:msg];
- }
iOS - 发送邮件的更多相关文章
- ios发送邮件
方法一: 1.需要引入库MessageUI.framework #import <MessageUI/MessageUI.h> #import<MessageUI/MFMailCom ...
- iOS开发-发送邮件(E-mail)方法整理合集(共3种)
前言:在IOS开发中,有时候我们会需要用到邮件发送的功能.比如,接收用户反馈和程序崩溃通知等等.其实这个功能是很常用的,因为我目前就有发送邮件的开发需求,所以顺便整理下IOS发送邮件的方法. IOS原 ...
- 发送邮件(E-mail)方法整理合集
在IOS开发中,有时候我们会需要用到邮件发送的功能.比如,接收用户反馈和程序崩溃通知等等.其实这个功能是很常用的,因为我目前就有发送邮件的开发需求,所以顺便整理下IOS发送邮件的方法. IOS原生自带 ...
- ios 后台发送邮件之SKPSMTPMessage的使用
skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git 1.由于skpsmtpmessage是非ARC ...
- [原]IOS 后台发送邮件
skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git -(void)statrUpLoad:(id) ...
- iOS调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的
在iOS开发中,经常需要调用其它App,如拨打电话.发送邮件等.UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App. 通 ...
- iOS中发送短信/发送邮件的实现 韩俊强的博客
需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/ ...
- 47.iOS跳转AppStore评分和发送邮件
1.跳转到AppStore评分 应用地址是关键:IOS 设备,手机搜索应用,拷贝链接 NSString *appStr =@"https://itunes.apple.com/cn/app/ ...
- mono中发送邮件并保存本次收件人的地址
在ios端mono开发中,发送邮件可以选择调用ios原生email程序.有两种方式实现这种功能,一是程序跳转到ipad中email程序,另外一种是将发送邮件的界面在自己应用里弹出. 首先第一种方式的代 ...
随机推荐
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- linux上配置jdk+Apache
一:安装jdk下载将jdk加压后放到/usr/local目录下: [root@master ~]#chmod 755 jdk-6u5-linux-x64.bin [root@master ~]# ./ ...
- 如何从零开始学习DIV+CSS
CSS是样式,DIV是层.DIV+CSS是网站标准(web标准),通常为了说明与HTML网页设计语言中的表格(table)定位方式的区别.因为XHTML网站设计标准中,不再使用表格定位技术,而是采用D ...
- 使用AOP 实现Redis缓存注解,支持SPEL
公司项目对Redis使用比较多,因为之前没有做AOP,所以缓存逻辑和业务逻辑交织在一起,维护比较艰难所以最近实现了针对于Redis的@Cacheable,把缓存的对象依照类别分别存放到redis的Ha ...
- Nexus搭建Maven服务器
参考:http://blog.csdn.net/ichsonx/article/details/14642897 1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央 ...
- linux下安装apache2.4
linux安装Apache2步骤如下 apr 下载地址 http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz 安装过程 tar -xzvf apr- ...
- elfiner-servlet 2.x已开源!
通过近一周的努力,elfiner-servlet 2.x基本搞定! 已提交github,开源之!请各位享用~~ 对elfinder不熟悉的请访问:http://elfinder.org 一个很不错的文 ...
- Orchard 学习-手动安装Orchard
通过Orchard zip 文件手动配置网站 这篇文章将引导你如果通过Zip文件来安装Orchard. 我们会使用三种不同的方法来承载Orchard: IIS. WebMatrix and IIS E ...
- html5 video.js 使用及兼容所有浏览器
废话少说,直接开始 一.准备材料 video.js下载: http://www.videojs.com/ 二.代码 引入相关文件:(必须放在文件的开头,也是说一定要放在video标签之前) 贴入htm ...
- 20160405javaweb之jdbc
一.数据库驱动的概念.JDBC 数据库厂商提供的用来操作数据库用的jar包就是数据库驱动.各个厂商如果提供各自的数据库驱动的话会导致开发人员学习成本太高,所以sun公司提供了一套数据库驱动应该遵循的接 ...