1.新建立一个项目,view based application(with storyboard.ARC)
2.需要引入UIMessage Library ,如下图
3.编辑ViewController.h文件
如下
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
-(IBAction)sendMail:(id)sender;
@end
4.在ViewController.m文件中添加如下方法
-(IBAction)sendMail:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:@"Apple , Welcome to china."];
NSArray *toRecipients = [NSArray arrayWithObjects:@"bu.xianggang@gmail.com", nil];
[mail setToRecipients:toRecipients];
[mail setCcRecipients:toRecipients];
NSString *emailBody = @”hello apple”;
[mail setMessageBody:emailBody isHTML:NO];
mail.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:mail animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”ERROR” message:@”Email is not supported on your device” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles: nil];
[alert show];
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@”Cancelled”);
break;
case MFMailComposeResultSaved:
NSLog(@”Message saved in drafts folder”);
break;
case MFMailComposeResultSent:
NSLog(@”Message is sent”);
break;
case MFMailComposeResultFailed:
NSLog(@”Message not sent due to error”);
break;
default:
NSLog(@”Mail not sent”);
break;
}
[self dismissModalViewControllerAnimated:YES];
}
OK,大功搞成.
分享到:
相关推荐
ios调用系统的API达到发送邮件的功能。
IOS应用源码之使用MessageUI发送带附件的邮件 .zip
IOS 两种发送电子邮件示例代码,包含上传附件。
完美解析系统发邮件功能,发送事件+发送成功结果事件委托
这是一篇介绍IOS实现如何发邮件功能的文档,其中包含实现代码
IOS打电话、发短信、发邮件的封装类,使用非常方便
这是一个ios利用smtp发送邮件的sample。它使用了一个开源的框架,适合于不使用ios自带邮件发送的项目使用
当IOS运行过程中产生异常,程序CRASH,自动将异常发送到指定邮箱。通过邮箱查看跟踪CRASH原因。
实现ios邮件客户端的代码的客户端 做iOS 邮件开发的可以用到 需要自己下载
传智播客iOS6免费公开课程-调用打电话发短信发邮件打开浏览器
ios app异常处理可以发送邮件,ios app异常处理可以发送邮件的代码实现。
iOS Demo 实现 打电话发邮件读短信功能
iOS之短信,邮件,通信录的实现,欢迎大家下载学习
IOS开发
这是用来发送邮件的demo,需要真机
在一个窗口打开系统中的APP
IOS应用源码——使用MessageUI发送带附加的邮件MailTest.rar
基于iOS平台的安全邮件客户端的设计与实现,曹景军,周锋,伴随着移动互联网和智能手机的发展,对移动终端中内容的保护成为移动领域的焦点。本文设计并实现了C/S架构的邮件加密系统,终端程
ios邮件中收件人像胶囊的显示的源代码, 包括胶囊形状的联系人。还有一个简单的邮件app的源代码。
IOS通过两种方法发送Email的示例源代码。