方法一:

1.需要引入库MessageUI.framework

#import <MessageUI/MessageUI.h>

#import<MessageUI/MFMailComposeViewController.h>

2.@interface ViewController : UIXXXXXViewController <..., MFMailComposeViewControllerDelegate>

@end

3.发送执行代码。事先验证相关支持。

    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (!mailClass) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"发送邮件"
message:@"当前系统版本不支持应用内发送邮件功能,您可以使用mailto方法代替"
delegate:self
cancelButtonTitle:@"我知道啦"
otherButtonTitles: nil] autorelease];
[alert show]; return;
}
if (![mailClass canSendMail]) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"发送邮件"
message:@"用户没有设置邮件账户"
delegate:self
cancelButtonTitle:@"我知道啦"
otherButtonTitles: nil] autorelease];
[alert show];
return;
} MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:@"Hello, World!"];
[mc setToRecipients:[NSArray arrayWithObject:@"xxxxx@163.com"]];
// [mc setCcRecipients:[NSArray arrayWithObject:@"xxxxx@163.com"]];
// [mc setBccRecipients:[NSArray arrayWithObject:@"secret@gmail.com"]];
[mc setMessageBody:@"Hello,slick!!!\n\nCome here, I need you!" isHTML:NO]; // 添加一张图片
UIImage *addPic = [UIImage imageNamed: @"Icon@2x.png"];
NSData *imageData = UIImagePNGRepresentation(addPic); // png
[mc addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"]; //添加一个pdf附件
NSString *file = [self fullBundlePathFromRelativePath:@"高质量C++编程指南.pdf"];
NSData *pdf = [NSData dataWithContentsOfFile:file];
[mc addAttachmentData: pdf mimeType: @"" fileName: @"高质量C++编程指南.pdf"]; [self presentViewController:mc animated:YES completion:nil];
[mc release];

回调函数:

- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error {
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];
}

方法二:

url方式

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

即 [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"]];

还可使用skpsmtpmessage这样的第三方控件。

ios发送邮件的更多相关文章

  1. iOS - 发送邮件

    IOS系统框架提供的两种发送Email的方法:openURL 和 MFMailComposeViewController.借助这两个方法,我们可以轻松的在应用里加入如用户反馈这类需要发送邮件的功能. ...

  2. iOS开发-发送邮件(E-mail)方法整理合集(共3种)

    前言:在IOS开发中,有时候我们会需要用到邮件发送的功能.比如,接收用户反馈和程序崩溃通知等等.其实这个功能是很常用的,因为我目前就有发送邮件的开发需求,所以顺便整理下IOS发送邮件的方法. IOS原 ...

  3. 发送邮件(E-mail)方法整理合集

    在IOS开发中,有时候我们会需要用到邮件发送的功能.比如,接收用户反馈和程序崩溃通知等等.其实这个功能是很常用的,因为我目前就有发送邮件的开发需求,所以顺便整理下IOS发送邮件的方法. IOS原生自带 ...

  4. ios 后台发送邮件之SKPSMTPMessage的使用

    skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git 1.由于skpsmtpmessage是非ARC ...

  5. [原]IOS 后台发送邮件

    skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git -(void)statrUpLoad:(id) ...

  6. iOS调用其它App,如拨打电话、发送邮件等。UIApplication:openURL:方法是实现这一目的的

    在iOS开发中,经常需要调用其它App,如拨打电话.发送邮件等.UIApplication:openURL:方法是实现这一目的的最简单方法,该方法一般通过提供的url参数的模式来调用不同的App. 通 ...

  7. iOS中发送短信/发送邮件的实现 韩俊强的博客

    需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/ ...

  8. 47.iOS跳转AppStore评分和发送邮件

    1.跳转到AppStore评分 应用地址是关键:IOS 设备,手机搜索应用,拷贝链接 NSString *appStr =@"https://itunes.apple.com/cn/app/ ...

  9. mono中发送邮件并保存本次收件人的地址

    在ios端mono开发中,发送邮件可以选择调用ios原生email程序.有两种方式实现这种功能,一是程序跳转到ipad中email程序,另外一种是将发送邮件的界面在自己应用里弹出. 首先第一种方式的代 ...

随机推荐

  1. svn文件图

  2. django-xadmin ModelAdmin中定义object_list_template无效的问题

    环境:https://github.com/y2kconnect/xadmin-for-python3.git python3.5.2 django1.9.12 object_list_templat ...

  3. 我眼中的ASP.NET Core之微服务

    ### 前言 前几天在博客园看到有园友在分享关于微软的一个微服务架构的示例程序,想必大家都已经知道了,那就是[eShopOnContainers](https://github.com/dotnet- ...

  4. Spring 学习一

    Spring工作机制及为什么要用? 1.springmvc将所有的请求都提交给DispacherServlet,他会委托应用系统的其他模块负责对请求进行真正的处理工作. 2.DispacherServ ...

  5. mongodb远程连接配置

    mongodb远程连接配置如下: 1.修改配置文件mongodb.conf 命令:vim /etc/mongodb.conf 把 bind_ip=127.0.0.1 这一行注释掉或者是修改成 bind ...

  6. v2013调试无法访问此网站 localhost 拒绝了我们的连接请求

    问题描述:          别人给的服务器代码,在本地部署以后调试的,localhost:8080 可以访问,localhost:2524访问不了需要改什么配置吗 解决思路:           这 ...

  7. javascript之原型(prototype)

    今天是第一次写博客,写点在javascript中重要的一个概念----原型(prototype): 原型,顾名思义,就是一切事物的模板. 柏拉图在<理想国>卷10中说:"床不是有 ...

  8. Java IO学习笔记(四)打印流

    1.只有输出流才有打印流:PrintWriter和PrintStream分别针对字符和字节,提供了重载的print,Println方法用于多种数据类型的输出.PrintWriter和PrintStre ...

  9. 简单来说一下ui-route

    UI-Router被认为是AngularUI为开发者提供的最实用的一个模块,它是一个让开发者能够根据URL状态或者说是'机器状态'来组织和控制界面UI的渲染,而不是仅仅只改变路由(传统AngularJ ...

  10. xhr.readyState就绪状态

    0:初始化,XMLHttpRequest对象还没有完成初始化 1:载入,XMLHttpRequest对象开始发送请求 2:载入完成,XMLHttpRequest对象的请求发送完成 3:解析,XMLHt ...