博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS使用MessageUI Framework 发送邮件
阅读量:6515 次
发布时间:2019-06-24

本文共 1665 字,大约阅读时间需要 5 分钟。

hot3.png

1. 导入框架:MessageUI.framework
2. 添加协议:<MFMailComposeViewControllerDelegate>

3. #import <MessageUI/MessageUI.h>

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];//设置委托mc.mailComposeDelegate = self;//设置邮件主题[mc setSubject:@"Hello World!"];//设置收件人[mc setToRecipients:[NSArray arrayWithObjects:@"zhuqi@163.com"]];//设置cc[mc setCcRecipients:[NSArray arrayWithObjects:@"78788@qq.com"]];//设置bcc[mc setBccRecipients:[NSArray arrayWithObjects:@"789@qq.com"]];//设置邮件内容//[mc setMessageBody:@"This is a test mail" isHTML:NO];//设置邮件内容,支持HTML[mc setMessageBody:@"Hello, Joe!
What do you know?" isHTML:YES];//为邮件添加附件NSString *path = [[NSBundle mainBundle] pathForResource:@"orange" ofType:@"png"];NSData *data = [NSData dataWithContentsOfFile:path];[mc addAttachmentData:data mimeType:@"image/png" fileName:@"orange"];[self presentModalViewController:mc animated:YES];[mc release];#pragma mark -#pragma mark Delegate Method-(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 MFMailComposeResultSend: NSLog(@"Mail send..."); break; case MFMailComposeResultFailed: NSLog(@"Mail send errored:%@...",[error localizedDescription]); break; default: break; } [self dismissModalViewControllerAnimated:YES];}

转载于:https://my.oschina.net/CarlHuang/blog/135458

你可能感兴趣的文章
正则匹配之url的匹配
查看>>
SGE:qsub/qstat/qdel/qhost 任务投递和监控
查看>>
【图解】javaScript组成结构
查看>>
刚接触机器学习这一个月我都做了什么?
查看>>
java泛型具体解释
查看>>
从头认识java-15.7 Map(5)-介绍HashMap的工作原理-Key变了,能不能get出原来的value?(偶尔作为面试题)...
查看>>
AngularJS的简单表单验证
查看>>
【ArcGIS】ArcGIS Android SDK
查看>>
译《Time, Clocks, and the Ordering of Events in a Distributed System》
查看>>
python 保留两位小数
查看>>
Spring4-@Enable** 注解的实现原理
查看>>
Virtualbox中Linux添加新磁盘并创建分区
查看>>
CentOS6.5安装Elasticsearch1.7.5
查看>>
Windows平台注册mysql服务
查看>>
stl中Multimaps的基本用法
查看>>
Spring @Transactional ——事务回滚
查看>>
Ubuntu 修改环境变量
查看>>
(轉載) 英中繁簡編程術語對照 (C/C++)
查看>>
路由器DNS中继(小知识)
查看>>
微软图表控件使用拾遗
查看>>