标签:
使用MessageUI.framework框架除了可以发送短信,还能发送Email,步骤如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import UIKit import MessageUI class ViewController : UIViewController , UINavigationControllerDelegate , MFMailComposeViewControllerDelegate { override func viewDidLoad() { super .viewDidLoad() //首先要判断设备具不具备发送邮件功能 if MFMailComposeViewController .canSendMail(){ let controller = MFMailComposeViewController () //设置代理 controller.mailComposeDelegate = self //设置主题 controller.setSubject( "我是邮件标题" ) //设置收件人 controller.setToRecipients([ "a1@hangge.com" , "a2@hangge.com" ]) //设置抄送人 controller.setCcRecipients([ "b1@hangge.com" , "b2@hangge.com" ]) //设置密送人 controller.setBccRecipients([ "c1@hangge.com" , "c2@hangge.com" ]) //添加图片附件 var path = NSBundle .mainBundle().pathForResource( "hangge.png" , ofType: "" ) var myData = NSData (contentsOfFile: path!) controller.addAttachmentData(myData, mimeType: "image/png" , fileName: "swift.png" ) //设置邮件正文内容(支持html) controller.setMessageBody( "我是邮件正文" , isHTML: false ) //打开界面 self .presentViewController(controller, animated: true , completion: nil ) } else { println ( "本设备不能发送邮件" ) } } //发送邮件代理方法 func mailComposeController(controller: MFMailComposeViewController !, didFinishWithResult result: MFMailComposeResult , error: NSError !) { controller.dismissViewControllerAnimated( true , completion: nil ) switch result.value{ case MFMailComposeResultSent .value: println ( "邮件已发送" ) case MFMailComposeResultCancelled .value: println ( "邮件已取消" ) case MFMailComposeResultSaved .value: println ( "邮件已保存" ) case MFMailComposeResultFailed .value: println ( "邮件发送失败" ) default : println ( "邮件没有发送" ) break } } override func didReceiveMemoryWarning() { super .didReceiveMemoryWarning() } } |
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4843608.html